mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
fix newlines with wsh getvar. (#1349)
output a newline when running in a tty and don't output a newline when running out of a tty. add options -n and -N to override that behavior
This commit is contained in:
parent
b6ce2cd022
commit
c37d292224
@ -30,6 +30,8 @@ var (
|
|||||||
getVarAllVars bool
|
getVarAllVars bool
|
||||||
getVarNullTerminate bool
|
getVarNullTerminate bool
|
||||||
getVarLocal bool
|
getVarLocal bool
|
||||||
|
getVarFlagNL bool
|
||||||
|
getVarFlagNoNL bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -38,6 +40,19 @@ func init() {
|
|||||||
getVarCmd.Flags().BoolVar(&getVarAllVars, "all", false, "get all variables")
|
getVarCmd.Flags().BoolVar(&getVarAllVars, "all", false, "get all variables")
|
||||||
getVarCmd.Flags().BoolVarP(&getVarNullTerminate, "null", "0", false, "use null terminators in output")
|
getVarCmd.Flags().BoolVarP(&getVarNullTerminate, "null", "0", false, "use null terminators in output")
|
||||||
getVarCmd.Flags().BoolVarP(&getVarLocal, "local", "l", false, "get variables local to block")
|
getVarCmd.Flags().BoolVarP(&getVarLocal, "local", "l", false, "get variables local to block")
|
||||||
|
getVarCmd.Flags().BoolVarP(&getVarFlagNL, "newline", "n", false, "print newline after output")
|
||||||
|
getVarCmd.Flags().BoolVarP(&getVarFlagNoNL, "no-newline", "N", false, "do not print newline after output")
|
||||||
|
}
|
||||||
|
|
||||||
|
func shouldPrintNewline() bool {
|
||||||
|
isTty := getIsTty()
|
||||||
|
if getVarFlagNL {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if getVarFlagNoNL {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return isTty
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVarRun(cmd *cobra.Command, args []string) error {
|
func getVarRun(cmd *cobra.Command, args []string) error {
|
||||||
@ -87,7 +102,11 @@ func getVarRun(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteStdout("%s\n", resp.Val)
|
WriteStdout("%s", resp.Val)
|
||||||
|
if shouldPrintNewline() {
|
||||||
|
WriteStdout("\n")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,13 @@ func preRunSetupRpcClient(cmd *cobra.Command, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getIsTty() bool {
|
||||||
|
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type RunEFnType = func(*cobra.Command, []string) error
|
type RunEFnType = func(*cobra.Command, []string) error
|
||||||
|
|
||||||
func activityWrap(activityStr string, origRunE RunEFnType) RunEFnType {
|
func activityWrap(activityStr string, origRunE RunEFnType) RunEFnType {
|
||||||
|
Loading…
Reference in New Issue
Block a user