Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Flag Generation #881

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,28 @@ sudo: false
dist: trusty
osx_image: xcode8.3
go:
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x

os:
- linux
- osx

env:
GO111MODULE=on

cache:
directories:
- node_modules

before_script:
- go get github.com/shurcooL/vfsgen || true
- go get github.com/shurcooL/httpfs/union || true
- go get github.com/urfave/gfmrun/... || true
- go get github.com/urfave/gfmrun/cmd/gfmrun
- go get golang.org/x/tools/cmd/goimports
- if [ ! -f node_modules/.bin/markdown-toc ] ; then
npm install markdown-toc ;
fi
- npm install markdown-toc
- go mod tidy

script:
- go run build.go generate
- go run build.go vet
- go run build.go test
- go run build.go gfmrun
Expand Down
71 changes: 0 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -914,76 +914,6 @@ func main() {
}
```

### Combining short options

Traditional use of options using their shortnames look like this:

```
$ cmd -s -o -m "Some message"
```

Suppose you want users to be able to combine options with their shortnames. This
can be done using the `UseShortOptionHandling` bool in your app configuration,
or for individual commands by attaching it to the command configuration. For
example:

<!-- {
"args": ["short", "&#45;som", "Some message"],
"output": "serve: true\noption: true\nmessage: Some message\n"
} -->
``` go
package main

import (
"fmt"
"log"
"os"

"github.com/urfave/cli"
)

func main() {
app := cli.NewApp()
app.UseShortOptionHandling = true
app.Commands = []cli.Command{
{
Name: "short",
Usage: "complete a task on the list",
Flags: []cli.Flag{
cli.BoolFlag{Name: "serve, s"},
cli.BoolFlag{Name: "option, o"},
cli.StringFlag{Name: "message, m"},
},
Action: func(c *cli.Context) error {
fmt.Println("serve:", c.Bool("serve"))
fmt.Println("option:", c.Bool("option"))
fmt.Println("message:", c.String("message"))
return nil
},
},
}

err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
```

If your program has any number of bool flags such as `serve` and `option`, and
optionally one non-bool flag `message`, with the short options of `-s`, `-o`,
and `-m` respectively, setting `UseShortOptionHandling` will also support the
following syntax:

```
$ cmd -som "Some message"
```

If you enable `UseShortOptionHandling`, then you must not use any flags that
have a single leading `-` or this will result in failures. For example,
`-option` can no longer be used. Flags with two leading dashes (such as
`--options`) are still valid.

### Bash Completion

You can enable completion commands by setting the `EnableBashCompletion`
Expand Down Expand Up @@ -1435,7 +1365,6 @@ func main() {
cli.Uint64Flag{Name: "bigage"},
}
app.EnableBashCompletion = true
app.UseShortOptionHandling = true
app.HideHelp = false
app.HideVersion = false
app.BashComplete = func(c *cli.Context) {
Expand Down
23 changes: 0 additions & 23 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ func main() {
Name: "toc",
Action: TocActionFunc,
},
cli.Command{
Name: "generate",
Action: GenActionFunc,
},
}

err := app.Run(os.Args)
Expand Down Expand Up @@ -166,22 +162,3 @@ func TocActionFunc(_ *cli.Context) error {

return nil
}

func GenActionFunc(_ *cli.Context) error {
err := runCmd("go", "generate", "flag-gen/main.go")
if err != nil {
return err
}

err = runCmd("go", "generate", "cli.go")
if err != nil {
return err
}

err = runCmd("git", "diff", "--exit-code")
if err != nil {
return err
}

return nil
}
3 changes: 1 addition & 2 deletions docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package cli
import (
"bytes"
"fmt"
"github.com/cpuguy83/go-md2man/v2/md2man"
"io"
"sort"
"strings"
"text/template"

"github.com/cpuguy83/go-md2man/md2man"
)

// ToMarkdown creates a markdown string for the `*App`
Expand Down
1 change: 0 additions & 1 deletion flag-gen/.gitignore

This file was deleted.

55 changes: 0 additions & 55 deletions flag-gen/assets_generate.go

This file was deleted.

Loading