mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-23 15:41:02 +00:00
Migrate from flag to flaggy
- 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
This commit is contained in:
parent
a51bb830a5
commit
9a41c773ea
1 changed files with 16 additions and 12 deletions
28
main.go
28
main.go
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -10,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
"github.com/integrii/flaggy"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/app"
|
"github.com/jesseduffield/lazydocker/pkg/app"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||||
"github.com/jesseduffield/yaml"
|
"github.com/jesseduffield/yaml"
|
||||||
|
|
@ -21,19 +21,23 @@ var (
|
||||||
date string
|
date string
|
||||||
buildSource = "unknown"
|
buildSource = "unknown"
|
||||||
|
|
||||||
configFlag = flag.Bool("config", false, "Print the current default config")
|
configFlag = false
|
||||||
debuggingFlag = flag.Bool("debug", false, "a boolean")
|
debuggingFlag = false
|
||||||
versionFlag = flag.Bool("v", false, "Print the current version")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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
|
var buf bytes.Buffer
|
||||||
yaml.NewEncoder(&buf).Encode(config.GetDefaultConfig())
|
yaml.NewEncoder(&buf).Encode(config.GetDefaultConfig())
|
||||||
fmt.Printf("%v\n", buf.String())
|
fmt.Printf("%v\n", buf.String())
|
||||||
|
|
@ -41,9 +45,9 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for now we're always in debug mode so we're not passing *debuggingFlag
|
// 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 {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue