Skip to content

Commit

Permalink
Merge pull request #2 from joseluisq/feature/help_and_version_flags
Browse files Browse the repository at this point in the history
Add version and preliminary help flags
  • Loading branch information
joseluisq authored Nov 10, 2020
2 parents 666ba0d + 7de0878 commit 2a3de56
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 297 deletions.
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cline [![Build Status](https://travis-ci.com/joseluisq/cline.svg?branch=master)](https://travis-ci.com/joseluisq/cline) [![codecov](https://codecov.io/gh/joseluisq/cline/branch/master/graph/badge.svg)](https://codecov.io/gh/joseluisq/cline) [![Go Report Card](https://goreportcard.com/badge/github.com/joseluisq/cline)](https://goreportcard.com/report/github.com/joseluisq/cline) [![GoDoc](https://godoc.org/github.com/joseluisq/cline?status.svg)](https://pkg.go.dev/github.com/joseluisq/cline)

> A fast and lightweight CLI package for Go with no dependencies.
> A fast and lightweight CLI package for Go without external dependencies.
WIP project under **active** development.

Expand Down Expand Up @@ -31,36 +31,36 @@ import (
func main() {
app := cli.New()
app.Name = "enve"
app.Summary = "run a program in a modified environment using .env files"
app.Summary = "Run a program in a modified environment using .env files"
app.Flags = []cli.Flag{
cli.FlagString{
Name: "file",
Summary: "load environment variables from a file path",
Summary: "Load environment variables from a file path",
Value: ".env",
Aliases: []string{"f"},
},
cli.FlagBool{
Name: "verbose",
Summary: "load environment variables from a file path",
Summary: "Enable more verbose info",
Value: false,
Aliases: []string{"v"},
EnvVar: "ENV_FILE",
EnvVar: "ENV_VERBOSE",
},
}
app.Commands = []cli.Cmd{
{
Name: "info",
Summary: "show command information",
Summary: "Show command information",
Flags: []cli.Flag{
cli.FlagInt{
Name: "version",
Summary: "enable more verbose command information",
Summary: "Enable more verbose command information",
Value: 10,
Aliases: []string{"z"},
},
cli.FlagBool{
Name: "detailed",
Summary: "enable info details",
Summary: "Enable info details",
Value: true,
Aliases: []string{"d"},
},
Expand All @@ -85,11 +85,29 @@ func main() {
fmt.Printf("App Flag `verbose` opted: `%s`\n", ctx.Flags.StringSlice("verbose"))
return nil
}
if err := app.Run(); err != nil {
if err := app.Run(os.Args); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

// OUTPUT:
//
// go run examples/main.go -h
// NAME: enve [OPTIONS] COMMAND

// Run a program in a modified environment using .env files

// OPTIONS:
// --file Load environment variables from a file path
// --verbose Enable more verbose info
// --version Prints version information
// --help Prints help information

// COMMANDS:
// info Show command information

// Run 'enve COMMAND --help' for more information on a command
```

## Contributions
Expand Down
Loading

0 comments on commit 2a3de56

Please sign in to comment.