Skip to content

Commit

Permalink
Migrate from flag to flaggy
Browse files Browse the repository at this point in the history
- Prerequisite for supporting multiple -f flags
- Migrate the existing flag use to flaggy, no new flags introduced yet
- Add name/description/repo to flaggy help output
- Use flaggy for version flag
  • Loading branch information
Callum McIntyre committed Jul 1, 2019
1 parent a51bb83 commit 9a41c77
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package main

import (
"bytes"
"flag"
"fmt"
"log"
"os"
"runtime"

"github.com/docker/docker/client"
"github.com/go-errors/errors"
"github.com/integrii/flaggy"
"github.com/jesseduffield/lazydocker/pkg/app"
"github.com/jesseduffield/lazydocker/pkg/config"
"github.com/jesseduffield/yaml"
Expand All @@ -21,29 +21,33 @@ var (
date string
buildSource = "unknown"

configFlag = flag.Bool("config", false, "Print the current default config")
debuggingFlag = flag.Bool("debug", false, "a boolean")
versionFlag = flag.Bool("v", false, "Print the current version")
configFlag = false
debuggingFlag = false
)

func main() {
flag.Parse()
if *versionFlag {
fmt.Printf("commit=%s, build date=%s, build source=%s, version=%s, os=%s, arch=%s\n", commit, date, buildSource, version, runtime.GOOS, runtime.GOARCH)
os.Exit(0)
}

if *configFlag {
flaggy.SetName("lazydocker")
flaggy.SetDescription("The lazier way to manage everything docker")
flaggy.DefaultParser.AdditionalHelpPrepend = "https://github.com/jesseduffield/lazydocker"

flaggy.Bool(&configFlag, "c", "config", "Print the current default config")
flaggy.Bool(&debuggingFlag, "d", "debug", "a boolean")
flaggy.SetVersion(fmt.Sprintf("commit=%s, build date=%s, build source=%s, version=%s, os=%s, arch=%s\n", commit, date, buildSource, version, runtime.GOOS, runtime.GOARCH))

flaggy.Parse()

if configFlag {
var buf bytes.Buffer
yaml.NewEncoder(&buf).Encode(config.GetDefaultConfig())
fmt.Printf("%v\n", buf.String())
os.Exit(0)
}

// for now we're always in debug mode so we're not passing *debuggingFlag
*debuggingFlag = true
debuggingFlag = true

appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, *debuggingFlag)
appConfig, err := config.NewAppConfig("lazydocker", version, commit, date, buildSource, debuggingFlag)
if err != nil {
log.Fatal(err.Error())
}
Expand Down

0 comments on commit 9a41c77

Please sign in to comment.