mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	Re-add command line help
This commit is contained in:
		
							parent
							
								
									7f3daaac59
								
							
						
					
					
						commit
						cd35d1e0a3
					
				| @ -6,11 +6,14 @@ import ( | ||||
| 	"path/filepath" | ||||
| 
 | ||||
| 	goFlags "github.com/jessevdk/go-flags" | ||||
| 	"github.com/olebedev/config" | ||||
| 	"github.com/wtfutil/wtf/help" | ||||
| 	"github.com/wtfutil/wtf/utils" | ||||
| ) | ||||
| 
 | ||||
| type Flags struct { | ||||
| 	Config  string `short:"c" long:"config" optional:"yes" description:"Path to config file"` | ||||
| 	Module  string `short:"m" long:"module" optional:"yes" description:"Display info about a specific module, i.e.: 'wtf -m=todo'"` | ||||
| 	Profile bool   `short:"p" long:"profile" optional:"yes" description:"Profile application memory usage"` | ||||
| 	Version bool   `short:"v" long:"version" description:"Show version info"` | ||||
| } | ||||
| @ -26,7 +29,12 @@ func (flags *Flags) ConfigFilePath() string { | ||||
| 	return flags.Config | ||||
| } | ||||
| 
 | ||||
| func (flags *Flags) Display(version string) { | ||||
| func (flags *Flags) Display(version string, config *config.Config) { | ||||
| 	if flags.HasModule() { | ||||
| 		help.Display(flags.Module, config) | ||||
| 		os.Exit(0) | ||||
| 	} | ||||
| 
 | ||||
| 	if flags.HasVersion() { | ||||
| 		fmt.Println(version) | ||||
| 		os.Exit(0) | ||||
| @ -37,6 +45,10 @@ func (flags *Flags) HasConfig() bool { | ||||
| 	return len(flags.Config) > 0 | ||||
| } | ||||
| 
 | ||||
| func (flags *Flags) HasModule() bool { | ||||
| 	return len(flags.Module) > 0 | ||||
| } | ||||
| 
 | ||||
| func (flags *Flags) HasVersion() bool { | ||||
| 	return flags.Version == true | ||||
| } | ||||
|  | ||||
							
								
								
									
										22
									
								
								help/help.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								help/help.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| package help | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 
 | ||||
| 	//"github.com/wtfutil/wtf/cfg" | ||||
| 	"github.com/olebedev/config" | ||||
| 	"github.com/wtfutil/wtf/maker" | ||||
| ) | ||||
| 
 | ||||
| func Display(moduleName string, config *config.Config) { | ||||
| 	if moduleName == "" { | ||||
| 		fmt.Println("\n  --module takes a module name as an argument, i.e: '--module=github'") | ||||
| 	} else { | ||||
| 		fmt.Printf("%s\n", helpFor(moduleName, config)) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func helpFor(moduleName string, config *config.Config) string { | ||||
| 	widget := maker.MakeWidget(nil, nil, moduleName, moduleName, config, config) | ||||
| 	return widget.HelpText() | ||||
| } | ||||
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							| @ -114,14 +114,13 @@ func main() { | ||||
| 
 | ||||
| 	flags := flags.NewFlags() | ||||
| 	flags.Parse() | ||||
| 	flags.Display(version) | ||||
| 	config := cfg.LoadConfigFile(flags.ConfigFilePath()) | ||||
| 	flags.Display(version, config) | ||||
| 
 | ||||
| 	cfg.MigrateOldConfig() | ||||
| 	cfg.CreateConfigDir() | ||||
| 	cfg.CreateConfigFile() | ||||
| 
 | ||||
| 	config := cfg.LoadConfigFile(flags.ConfigFilePath()) | ||||
| 
 | ||||
| 	if flags.Profile { | ||||
| 		defer profile.Start(profile.MemProfile).Stop() | ||||
| 	} | ||||
|  | ||||
| @ -64,6 +64,10 @@ func (widget *Widget) Render() { | ||||
| 	widget.Redraw(widget.CommonSettings.Title, content, false) | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) contentFrom(triggeredMonitors []datadog.Monitor) string { | ||||
|  | ||||
| @ -90,6 +90,10 @@ func (widget *Widget) Refresh() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) nextProject() { | ||||
|  | ||||
| @ -85,6 +85,10 @@ func (widget *Widget) Refresh() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) addCheckoutButton(form *tview.Form, fctn func()) { | ||||
|  | ||||
| @ -67,6 +67,10 @@ func (widget *Widget) Prev() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) buildRepoCollection(repoData map[string]interface{}) []*GithubRepo { | ||||
|  | ||||
| @ -73,6 +73,10 @@ func (widget *Widget) Prev() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) buildProjectCollection(projectData map[string]interface{}) []*GitlabProject { | ||||
|  | ||||
| @ -64,6 +64,10 @@ func (widget *Widget) Refresh() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) display() { | ||||
|  | ||||
| @ -79,6 +79,10 @@ func (widget *Widget) Refresh() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) addCheckoutButton(form *tview.Form, fctn func()) { | ||||
|  | ||||
| @ -47,6 +47,10 @@ func (widget *Widget) Refresh() { | ||||
| 	widget.Redraw(widget.CommonSettings.Title, widget.nbascore(), false) | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) nbascore() string { | ||||
| 	cur := time.Now().AddDate(0, 0, offset) // Go back/forward offset days | ||||
| 	curString := cur.Format("20060102")     // Need 20060102 format to feed to api | ||||
|  | ||||
| @ -55,6 +55,10 @@ func (w *Widget) Refresh() { | ||||
| 	w.render() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| func (w *Widget) render() { | ||||
| 	err := w.refreshSpotifyInfos() | ||||
| 	var content string | ||||
|  | ||||
| @ -165,6 +165,10 @@ func (w *Widget) Refresh() { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| func (w *Widget) createOutput() string { | ||||
| 	output := wtf.CenterText(fmt.Sprintf("[green]Now %v [white]\n", w.Info.Status), w.Width()) | ||||
| 	output += wtf.CenterText(fmt.Sprintf("[green]Title:[white] %v\n", w.Info.Title), w.Width()) | ||||
|  | ||||
| @ -63,6 +63,10 @@ func (widget *Widget) Refresh() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) display() { | ||||
|  | ||||
| @ -65,6 +65,10 @@ func (widget *Widget) SetList(list checklist.Checklist) { | ||||
| 	widget.list = list | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| // edit opens a modal dialog that permits editing the text of the currently-selected item | ||||
|  | ||||
| @ -77,6 +77,10 @@ func (w *Widget) Refresh() { | ||||
| 	w.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Keyboard Movement -------------------- */ | ||||
| 
 | ||||
| // Down selects the next item in the list | ||||
|  | ||||
| @ -54,6 +54,10 @@ func (widget *Widget) Refresh() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) display() { | ||||
|  | ||||
| @ -87,6 +87,10 @@ func (widget *Widget) Prev() { | ||||
| 	widget.display() | ||||
| } | ||||
| 
 | ||||
| func (widget *Widget) HelpText() string { | ||||
| 	return widget.KeyboardWidget.HelpText() | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *Widget) apiKeyValid() bool { | ||||
|  | ||||
| @ -112,6 +112,10 @@ func (widget *BarGraph) TextView() *tview.TextView { | ||||
| 	return widget.View | ||||
| } | ||||
| 
 | ||||
| func (widget *BarGraph) HelpText() string { | ||||
| 	return "No help available for this widget" | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *BarGraph) addView() *tview.TextView { | ||||
|  | ||||
| @ -78,7 +78,7 @@ func (widget *KeyboardWidget) InputCapture(event *tcell.EventKey) *tcell.EventKe | ||||
| 	return event | ||||
| } | ||||
| 
 | ||||
| func (widget *KeyboardWidget) helpText() string { | ||||
| func (widget *KeyboardWidget) HelpText() string { | ||||
| 
 | ||||
| 	str := "Keyboard commands for " + widget.settings.Module.Type + "\n\n" | ||||
| 
 | ||||
| @ -99,7 +99,7 @@ func (widget *KeyboardWidget) ShowHelp() { | ||||
| 		widget.app.SetFocus(widget.view) | ||||
| 	} | ||||
| 
 | ||||
| 	modal := NewBillboardModal(widget.helpText(), closeFunc) | ||||
| 	modal := NewBillboardModal(widget.HelpText(), closeFunc) | ||||
| 
 | ||||
| 	widget.pages.AddPage("help", modal, false, true) | ||||
| 	widget.app.SetFocus(modal) | ||||
|  | ||||
| @ -119,6 +119,10 @@ func (widget *TextWidget) Redraw(title, text string, wrap bool) { | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func (widget *TextWidget) HelpText() string { | ||||
| 	return fmt.Sprintf("\n  There is no help available for this widget") | ||||
| } | ||||
| 
 | ||||
| /* -------------------- Unexported Functions -------------------- */ | ||||
| 
 | ||||
| func (widget *TextWidget) addView() *tview.TextView { | ||||
|  | ||||
| @ -14,6 +14,7 @@ type Wtfable interface { | ||||
| 	Name() string | ||||
| 	SetFocusChar(string) | ||||
| 	TextView() *tview.TextView | ||||
| 	HelpText() string | ||||
| 
 | ||||
| 	Height() int | ||||
| 	Left() int | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user