github.com/wtfutil/wtf@v0.43.0/modules/cmdrunner/settings.go (about) 1 package cmdrunner 2 3 import ( 4 "github.com/olebedev/config" 5 "github.com/wtfutil/wtf/cfg" 6 "github.com/wtfutil/wtf/utils" 7 ) 8 9 const ( 10 defaultFocusable = true 11 defaultTitle = "CmdRunner" 12 ) 13 14 // Settings for the cmdrunner widget 15 type Settings struct { 16 *cfg.Common 17 18 args []string `help:"The arguments to the command, with each item as an element in an array. Example: for curl -I cisco.com, the arguments array would be ['-I', 'cisco.com']."` 19 cmd string `help:"The terminal command to be run, withouth the arguments. Ie: ping, whoami, curl."` 20 tail bool `help:"Automatically scroll to the end of the command output."` 21 pty bool `help:"Run the command in a pseudo-terminal. Some apps will behave differently if they feel in a terminal. For example, some apps will produce colorized output in a terminal, and non-colorized output otherwise. Default false" optional:"true"` 22 maxLines int `help:"Maximum number of lines kept in the buffer."` 23 workingDir string `help:"Working directory for command to run in" optional:"true"` 24 25 // The dimensions of the module 26 width int 27 height int 28 } 29 30 // NewSettingsFromYAML loads the cmdrunner portion of the WTF config 31 func NewSettingsFromYAML(name string, moduleConfig *config.Config, globalConfig *config.Config) *Settings { 32 settings := Settings{ 33 Common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, moduleConfig, globalConfig), 34 35 args: utils.ToStrs(moduleConfig.UList("args")), 36 workingDir: moduleConfig.UString("workingDir", "."), 37 cmd: moduleConfig.UString("cmd"), 38 pty: moduleConfig.UBool("pty", false), 39 tail: moduleConfig.UBool("tail", false), 40 maxLines: moduleConfig.UInt("maxLines", 256), 41 } 42 43 width, height, err := utils.CalculateDimensions(moduleConfig, globalConfig) 44 if err == nil { 45 settings.width = width 46 settings.height = height 47 } 48 49 return &settings 50 }