Skip to content

Commit

Permalink
Closes #72. --info flag displays module help text
Browse files Browse the repository at this point in the history
Usage:

        wtf -i=todo
        wtf --info=todo
  • Loading branch information
senorprogrammer committed May 30, 2018
1 parent a46ff5c commit d0da319
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions wtf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/senorprogrammer/wtf/gcal"
"github.com/senorprogrammer/wtf/git"
"github.com/senorprogrammer/wtf/github"
"github.com/senorprogrammer/wtf/help"
"github.com/senorprogrammer/wtf/jira"
"github.com/senorprogrammer/wtf/newrelic"
"github.com/senorprogrammer/wtf/opsgenie"
Expand Down Expand Up @@ -202,6 +203,10 @@ func main() {
cmdFlags := wtf.NewCommandFlags()
cmdFlags.Parse(version)

if cmdFlags.HasInfo() {
help.DisplayHelpInfo(cmdFlags.Info)
}

/* -------------------- end flag parsing and handling -------------------- */

// Responsible for creating the configuration directory and default
Expand Down
12 changes: 10 additions & 2 deletions wtf/command_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

type CommandFlags struct {
Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"`
Info string `short:"i" long:"info" optional:"yes" description:"Display info about the specified module"`
Version bool `short:"v" long:"version" description:"Show Version Info"`
}

Expand All @@ -20,6 +21,14 @@ func NewCommandFlags() *CommandFlags {

/* -------------------- Exported Functions -------------------- */

func (cmdFlags *CommandFlags) HasConfig() bool {
return len(cmdFlags.Config) > 0
}

func (cmdFlags *CommandFlags) HasInfo() bool {
return len(cmdFlags.Info) > 0
}

func (cmdFlags *CommandFlags) Parse(version string) {
parser := flags.NewParser(cmdFlags, flags.Default)
if _, err := parser.Parse(); err != nil {
Expand All @@ -28,14 +37,13 @@ func (cmdFlags *CommandFlags) Parse(version string) {
}
}

if len(cmdFlags.Config) == 0 {
if !cmdFlags.HasConfig() {
homeDir, err := Home()
if err != nil {
os.Exit(1)
}

cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml")
fmt.Printf(">> A: %s\n", cmdFlags.Config)
}

if cmdFlags.Version {
Expand Down
2 changes: 0 additions & 2 deletions wtf/config_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func CreateFile(fileName string) (string, error) {

// LoadConfigFile loads the config.yml file to configure the app
func LoadConfigFile(filePath string) *config.Config {
fmt.Printf(">> B: %s\n", filePath)

absPath, _ := ExpandHomeDir(filePath)

cfg, err := config.ParseYamlFile(absPath)
Expand Down

0 comments on commit d0da319

Please sign in to comment.