diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 26452b42ca..544ccfe8a5 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -14,7 +14,7 @@ jobs: test: strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] go: [1.18.x, 1.19.x] name: ${{ matrix.os }} @ Go ${{ matrix.go }} runs-on: ${{ matrix.os }} diff --git a/.gitignore b/.gitignore index 8df35c5657..9d1812002b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ vendor /.local/ /internal/ /site/ +package.json +package-lock.json diff --git a/LICENSE b/LICENSE index 42a597e29b..99d8559da8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016 Jeremy Saenz & Contributors +Copyright (c) 2023 Jeremy Saenz & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9c2cf851a3..c7dd62bc67 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,10 @@ cli === -[![Build Status](https://travis-ci.org/urfave/cli.svg?branch=master)](https://travis-ci.org/urfave/cli) -[![Windows Build Status](https://ci.appveyor.com/api/projects/status/rtgk5xufi932pb2v?svg=true)](https://ci.appveyor.com/project/urfave/cli) - -[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://godoc.org/github.com/urfave/cli) -[![codebeat](https://codebeat.co/badges/0a8f30aa-f975-404b-b878-5fab3ae1cc5f)](https://codebeat.co/projects/github-com-urfave-cli) +[![Run Tests](https://github.com/urfave/cli/actions/workflows/cli.yml/badge.svg?branch=v1-maint)](https://github.com/urfave/cli/actions/workflows/cli.yml) +[![Go Reference](https://pkg.go.dev/badge/github.com/urfave/cli/.svg)](https://pkg.go.dev/github.com/urfave/cli/) [![Go Report Card](https://goreportcard.com/badge/urfave/cli)](https://goreportcard.com/report/urfave/cli) -[![codecov](https://codecov.io/gh/urfave/cli/branch/master/graph/badge.svg)](https://codecov.io/gh/urfave/cli) +[![codecov](https://codecov.io/gh/urfave/cli/branch/v1-maint/graph/badge.svg)](https://codecov.io/gh/urfave/cli) cli is a simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line @@ -15,29 +12,19 @@ applications in an expressive way. ## Usage Documentation -Usage documentation exists for each major version - -- `v1` - [./docs/v1/manual.md](./docs/v1/manual.md) -- `v2` - 🚧 documentation for `v2` is WIP 🚧 +Usage documentation for `v1` is available [at the docs +site](https://cli.urfave.org/v1/getting-started/) or in-tree at +[./docs/v1/manual.md](./docs/v1/manual.md) ## Installation -Make sure you have a working Go environment. Go version 1.10+ is supported. [See -the install instructions for Go](http://golang.org/doc/install.html). - -### GOPATH - -Make sure your `PATH` includes the `$GOPATH/bin` directory so your commands can -be easily used: -``` -export PATH=$PATH:$GOPATH/bin -``` +Make sure you have a working Go environment. Go version 1.18+ is supported. ### Supported platforms -cli is tested against multiple versions of Go on Linux, and against the latest -released version of Go on OS X and Windows. For full details, see -[`./.travis.yml`](./.travis.yml) and [`./appveyor.yml`](./appveyor.yml). +cli is tested against multiple versions of Go on Linux, and against the latest released +version of Go on OS X and Windows. For full details, see +[./.github/workflows/cli.yml](./.github/workflows/cli.yml). ### Build tags @@ -62,19 +49,3 @@ import ( ) ... ``` - -### Using `v2` releases - -**Warning**: `v2` is in a pre-release state. - -``` -$ go get github.com/urfave/cli.v2 -``` - -```go -... -import ( - "github.com/urfave/cli.v2" // imports as package "cli" -) -... -``` diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 8ef2fea1a6..0000000000 --- a/appveyor.yml +++ /dev/null @@ -1,28 +0,0 @@ -version: "{build}" - -os: Windows Server 2016 - -image: Visual Studio 2017 - -clone_folder: c:\gopath\src\github.com\urfave\cli - -cache: - - node_modules - -environment: - GOPATH: C:\gopath - GOVERSION: 1.11.x - GO111MODULE: on - GOPROXY: https://proxy.golang.org - -install: - - set PATH=%GOPATH%\bin;C:\go\bin;%PATH% - - go version - - go env - - go get github.com/urfave/gfmrun/cmd/gfmrun - - go mod vendor - -build_script: - - go run build.go vet - - go run build.go test - - go run build.go gfmrun docs/v1/manual.md diff --git a/docs/v1/manual.md b/docs/v1/manual.md index 8d0481934e..ec0b4a097c 100644 --- a/docs/v1/manual.md +++ b/docs/v1/manual.md @@ -27,8 +27,8 @@ cli v1 manual * [Version Flag](#version-flag) + [Customization](#customization-2) + [Full API Example](#full-api-example) - * [Testing](#testing) - * [Migrating to V2](#migrating-to-v2) +- [Testing](#testing) +- [Migrating to V2](#migrating-to-v2) diff --git a/docs_test.go b/docs_test.go index f4bf1c54b6..f181df5a54 100644 --- a/docs_test.go +++ b/docs_test.go @@ -5,6 +5,8 @@ package cli import ( "testing" + + "github.com/stretchr/testify/require" ) func TestToMarkdownFull(t *testing.T) { @@ -53,6 +55,6 @@ func TestToMan(t *testing.T) { res, err := app.ToMan() // Then - expect(t, err, nil) + require.Nil(t, err) expectFileContent(t, "testdata/expected-doc-full.man", res) } diff --git a/fish_test.go b/fish_test.go index 62313f0bbb..b3b3ddc6fe 100644 --- a/fish_test.go +++ b/fish_test.go @@ -1,8 +1,10 @@ package cli import ( - "io/ioutil" + "os" "testing" + + "github.com/stretchr/testify/require" ) func testApp() *App { @@ -66,9 +68,9 @@ func testApp() *App { } func expectFileContent(t *testing.T, file, expected string) { - data, err := ioutil.ReadFile(file) - expect(t, err, nil) - expect(t, string(data), expected) + data, err := os.ReadFile(file) + require.Nil(t, err) + require.Equal(t, string(data), expected) } func TestFishCompletion(t *testing.T) { diff --git a/go.mod b/go.mod index 7d04d20167..48129b648f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,8 @@ module github.com/urfave/cli go 1.11 require ( - github.com/BurntSushi/toml v0.3.1 - github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d - gopkg.in/yaml.v2 v2.2.2 + github.com/BurntSushi/toml v1.2.1 + github.com/cpuguy83/go-md2man/v2 v2.0.2 + github.com/stretchr/testify v1.8.1 // indirect + gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index ef121ff5db..0bc5ad95cc 100644 --- a/go.sum +++ b/go.sum @@ -1,14 +1,25 @@ -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= +github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go116_test.go b/go116_test.go deleted file mode 100644 index f6b5524015..0000000000 --- a/go116_test.go +++ /dev/null @@ -1,28 +0,0 @@ -//go:build !go1.17 -// +build !go1.17 - -package cli - -import ( - "bytes" - "errors" - "flag" - "testing" -) - -func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) { - a := App{ - Flags: []Flag{ - StringFlag{Name: "--foo"}, - }, - Writer: bytes.NewBufferString(""), - } - - set := flag.NewFlagSet("", flag.ContinueOnError) - _ = set.Parse([]string{"", "---foo"}) - c := &Context{flagSet: set} - - err := a.RunAsSubcommand(c) - - expect(t, err, errors.New("bad flag syntax: ---foo")) -} diff --git a/go117_test.go b/go117_test.go deleted file mode 100644 index f40ec4ea82..0000000000 --- a/go117_test.go +++ /dev/null @@ -1,33 +0,0 @@ -//go:build go1.17 -// +build go1.17 - -package cli - -import ( - "bytes" - "flag" - "testing" -) - -func TestApp_RunAsSubCommandIncorrectUsage(t *testing.T) { - a := App{ - Flags: []Flag{ - StringFlag{Name: "--foo"}, - }, - Writer: bytes.NewBufferString(""), - } - - set := flag.NewFlagSet("", flag.ContinueOnError) - _ = set.Parse([]string{"", "---foo"}) - c := &Context{flagSet: set} - - // Go 1.17+ panics when invalid flag is given. - // Catch it here and consider the test passed. - defer func() { - if err := recover(); err == nil { - t.Fatal("expected error, got nothing") - } - }() - - _ = a.RunAsSubcommand(c) -} diff --git a/testdata/expected-doc-full.man b/testdata/expected-doc-full.man index 5190698fa3..ce75939766 100644 --- a/testdata/expected-doc-full.man +++ b/testdata/expected-doc-full.man @@ -5,7 +5,7 @@ .SH NAME .PP -greet \- Some app +greet - Some app .SH SYNOPSIS @@ -16,9 +16,9 @@ greet .RS .nf -[\-\-another\-flag|\-b] -[\-\-flag|\-\-fl|\-f]=[value] -[\-\-socket|\-s]=[value] +[--another-flag|-b] +[--flag|--fl|-f]=[value] +[--socket|-s]=[value] .fi .RE @@ -26,7 +26,7 @@ greet .SH DESCRIPTION .PP -app [first\_arg] [second\_arg] +app [first_arg] [second_arg] .PP \fBUsage\fP: @@ -43,13 +43,13 @@ greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...] .SH GLOBAL OPTIONS .PP -\fB\-\-another\-flag, \-b\fP: another usage text +\fB--another-flag, -b\fP: another usage text .PP -\fB\-\-flag, \-\-fl, \-f\fP="": +\fB--flag, --fl, -f\fP="": .PP -\fB\-\-socket, \-s\fP="": some 'usage' text (default: value) +\fB--socket, -s\fP="": some 'usage' text (default: value) .SH COMMANDS @@ -58,23 +58,23 @@ greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...] another usage test .PP -\fB\-\-another\-flag, \-b\fP: another usage text +\fB--another-flag, -b\fP: another usage text .PP -\fB\-\-flag, \-\-fl, \-f\fP="": +\fB--flag, --fl, -f\fP="": -.SS sub\-config, s, ss +.SS sub-config, s, ss .PP another usage test .PP -\fB\-\-sub\-command\-flag, \-s\fP: some usage text +\fB--sub-command-flag, -s\fP: some usage text .PP -\fB\-\-sub\-flag, \-\-sub\-fl, \-s\fP="": +\fB--sub-flag, --sub-fl, -s\fP="": .SH info, i, in .PP retrieve generic information -.SH some\-command \ No newline at end of file +.SH some-command \ No newline at end of file