Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: urfave/cli
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.5.0
Choose a base ref
...
head repository: urfave/cli
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.5.1
Choose a head ref
  • 11 commits
  • 11 files changed
  • 2 contributors

Commits on Feb 8, 2021

  1. Copy the full SHA
    ef9430e View commit details
  2. revert docs/v2/manual.md

    vipally committed Feb 8, 2021
    Copy the full SHA
    06f6815 View commit details

Commits on Apr 24, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    f1ce5c7 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    de58951 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    68da1cd View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    11b3a30 View commit details
  5. Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    f6c020f View commit details
  6. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b58a588 View commit details

Commits on Apr 26, 2022

  1. Merge branch 'ally_fix_multi_val' of ssh://github.com/vipally/cli int…

    …o vipally-ally_fix_multi_val
    meatballhat committed Apr 26, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    meatballhat Dan Buch
    Copy the full SHA
    6538e95 View commit details
  2. Merge pull request #1371 from urfave/release-metadata

    Cleaning up some release-related metadata & docs
    meatballhat authored Apr 26, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a07f0d1 View commit details
  3. Merge pull request #1377 from urfave/vipally-ally_fix_multi_val

    Accept multi-value input on slice flags (#1241)
    meatballhat authored Apr 26, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    76418f2 View commit details
Showing with 186 additions and 21 deletions.
  1. +1 −1 LICENSE
  2. +4 −0 README.md
  3. +34 −0 app_test.go
  4. +6 −0 docs/CHANGELOG.md
  5. +61 −0 docs/RELEASING.md
  6. +4 −0 flag.go
  7. +8 −6 flag_float64_slice.go
  8. +8 −6 flag_int64_slice.go
  9. +8 −6 flag_int_slice.go
  10. +4 −2 flag_string_slice.go
  11. +48 −0 flag_test.go
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 Jeremy Saenz & Contributors
Copyright (c) 2022 urfave/cli maintainers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -78,3 +78,7 @@ export PATH=$PATH:$GOPATH/bin
cli is tested against multiple versions of Go on Linux, and against the latest
released version of Go on OS X and Windows. This project uses Github Actions for
builds. To see our currently supported go versions and platforms, look at the [./.github/workflows/cli.yml](https://github.com/urfave/cli/blob/main/.github/workflows/cli.yml).

## License

See [`LICENSE`](./LICENSE)
34 changes: 34 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
@@ -390,6 +390,40 @@ func ExampleApp_Run_zshComplete() {
// h:Shows a list of commands or help for one command
}

func ExampleApp_Run_sliceValues() {
// set args for examples sake
os.Args = []string{"multi_values",
"--stringSclice", "parsed1,parsed2", "--stringSclice", "parsed3,parsed4",
"--float64Sclice", "13.3,14.4", "--float64Sclice", "15.5,16.6",
"--int64Sclice", "13,14", "--int64Sclice", "15,16",
"--intSclice", "13,14", "--intSclice", "15,16",
}
app := NewApp()
app.Name = "multi_values"
app.Flags = []Flag{
&StringSliceFlag{Name: "stringSclice"},
&Float64SliceFlag{Name: "float64Sclice"},
&Int64SliceFlag{Name: "int64Sclice"},
&IntSliceFlag{Name: "intSclice"},
}
app.Action = func(ctx *Context) error {
for i, v := range ctx.FlagNames() {
fmt.Printf("%d-%s %#v\n", i, v, ctx.Value(v))
}
err := ctx.Err()
fmt.Println("error:", err)
return err
}

_ = app.Run(os.Args)
// Output:
// 0-float64Sclice cli.Float64Slice{slice:[]float64{13.3, 14.4, 15.5, 16.6}, hasBeenSet:true}
// 1-int64Sclice cli.Int64Slice{slice:[]int64{13, 14, 15, 16}, hasBeenSet:true}
// 2-intSclice cli.IntSlice{slice:[]int{13, 14, 15, 16}, hasBeenSet:true}
// 3-stringSclice cli.StringSlice{slice:[]string{"parsed1", "parsed2", "parsed3", "parsed4"}, hasBeenSet:true}
// error: <nil>
}

func TestApp_Run(t *testing.T) {
s := ""

6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
> :warning: This document is no longer being actively maintained. Please see the
> [releases page](https://github.com/urfave/cli/releases) for all release notes
> and related hypermedia for releases `>= 1.22.5`, `>= 2.3.0`.
---

# Change Log

**ATTN**: This project uses [semantic versioning](http://semver.org/).
61 changes: 61 additions & 0 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Releasing urfave/cli

Releasing small batches often is [backed by
research](https://itrevolution.com/accelerate-book/) as part of the
virtuous cycles that keep teams and products healthy.

To that end, the overall goal of the release process is to send
changes out into the world as close to the time the commits were
merged to the `main` branch as possible. In this way, the community
of humans depending on this library are able to make use of the
changes they need **quickly**, which means they shouldn't have to
maintain long-lived forks of the project, which means they can get
back to focusing on the work on which they want to focus. This also
means that the @urfave/cli team should be able to focus on
delivering a steadily improving product with significantly eased
ability to associate bugs and regressions with specific releases.

## Process

- Release versions follow [semantic versioning](https://semver.org/)
- Releases are associated with **signed, annotated git tags**[^1].
- Release notes are **automatically generated**[^2].

In the `main` or `v1` branch, the current version is always
available via:

```sh
git describe --always --dirty --tags
```

**NOTE**: if the version reported contains `-dirty`, this is
indicative of a "dirty" work tree, which is not a great state for
creating a new release tag. Seek help from @urfave/cli teammates.

For example, given a described version of `v2.4.7-3-g68da1cd` and a
diff of `v2.4.7...` that contains only bug fixes, the next version
should be `v2.4.8`:

```sh
git tag -a -s -m 'Release 2.4.8' v2.4.8
git push origin v2.4.8
```

The tag push will trigger a GitHub Actions workflow. The remaining
steps require human intervention through the GitHub web view
although [automated solutions
exist](https://github.com/softprops/action-gh-release) that may be
adopted in the future.

- Open the [the new release page](https://github.com/urfave/cli/releases/new)
- At the top of the form, click on the `Choose a tag` select control and select `v2.4.8`
- In the `Write` tab below, click the `Auto-generate release notes` button
- At the bottom of the form, click the `Publish release` button
- :white_check_mark: you're done!

[^1]: This was not always true. There are many **lightweight git
tags** present in the repository history.

[^2]: This was not always true. The
[`docs/CHANGELOG.md`](./CHANGELOG.md) document used to be
manually maintained.
4 changes: 4 additions & 0 deletions flag.go
Original file line number Diff line number Diff line change
@@ -402,3 +402,7 @@ func flagFromEnvOrFile(envVars []string, filePath string) (val string, ok bool)
}
return "", false
}

func flagSplitMultiValues(val string) []string {
return strings.Split(val, ",")
}
14 changes: 8 additions & 6 deletions flag_float64_slice.go
Original file line number Diff line number Diff line change
@@ -43,12 +43,14 @@ func (f *Float64Slice) Set(value string) error {
return nil
}

tmp, err := strconv.ParseFloat(value, 64)
if err != nil {
return err
}
for _, s := range flagSplitMultiValues(value) {
tmp, err := strconv.ParseFloat(strings.TrimSpace(s), 64)
if err != nil {
return err
}

f.slice = append(f.slice, tmp)
f.slice = append(f.slice, tmp)
}
return nil
}

@@ -151,7 +153,7 @@ func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error {
if val != "" {
f.Value = &Float64Slice{}

for _, s := range strings.Split(val, ",") {
for _, s := range flagSplitMultiValues(val) {
if err := f.Value.Set(strings.TrimSpace(s)); err != nil {
return fmt.Errorf("could not parse %q as float64 slice value for flag %s: %s", f.Value, f.Name, err)
}
14 changes: 8 additions & 6 deletions flag_int64_slice.go
Original file line number Diff line number Diff line change
@@ -43,12 +43,14 @@ func (i *Int64Slice) Set(value string) error {
return nil
}

tmp, err := strconv.ParseInt(value, 0, 64)
if err != nil {
return err
}
for _, s := range flagSplitMultiValues(value) {
tmp, err := strconv.ParseInt(strings.TrimSpace(s), 0, 64)
if err != nil {
return err
}

i.slice = append(i.slice, tmp)
i.slice = append(i.slice, tmp)
}

return nil
}
@@ -151,7 +153,7 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error {
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
f.Value = &Int64Slice{}

for _, s := range strings.Split(val, ",") {
for _, s := range flagSplitMultiValues(val) {
if err := f.Value.Set(strings.TrimSpace(s)); err != nil {
return fmt.Errorf("could not parse %q as int64 slice value for flag %s: %s", val, f.Name, err)
}
14 changes: 8 additions & 6 deletions flag_int_slice.go
Original file line number Diff line number Diff line change
@@ -54,12 +54,14 @@ func (i *IntSlice) Set(value string) error {
return nil
}

tmp, err := strconv.ParseInt(value, 0, 64)
if err != nil {
return err
}
for _, s := range flagSplitMultiValues(value) {
tmp, err := strconv.ParseInt(strings.TrimSpace(s), 0, 64)
if err != nil {
return err
}

i.slice = append(i.slice, int(tmp))
i.slice = append(i.slice, int(tmp))
}

return nil
}
@@ -162,7 +164,7 @@ func (f *IntSliceFlag) Apply(set *flag.FlagSet) error {
if val, ok := flagFromEnvOrFile(f.EnvVars, f.FilePath); ok {
f.Value = &IntSlice{}

for _, s := range strings.Split(val, ",") {
for _, s := range flagSplitMultiValues(val) {
if err := f.Value.Set(strings.TrimSpace(s)); err != nil {
return fmt.Errorf("could not parse %q as int slice value for flag %s: %s", val, f.Name, err)
}
6 changes: 4 additions & 2 deletions flag_string_slice.go
Original file line number Diff line number Diff line change
@@ -42,7 +42,9 @@ func (s *StringSlice) Set(value string) error {
return nil
}

s.slice = append(s.slice, value)
for _, t := range flagSplitMultiValues(value) {
s.slice = append(s.slice, strings.TrimSpace(t))
}

return nil
}
@@ -160,7 +162,7 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
destination = f.Destination
}

for _, s := range strings.Split(val, ",") {
for _, s := range flagSplitMultiValues(val) {
if err := destination.Set(strings.TrimSpace(s)); err != nil {
return fmt.Errorf("could not parse %q as string value for flag %s: %s", val, f.Name, err)
}
48 changes: 48 additions & 0 deletions flag_test.go
Original file line number Diff line number Diff line change
@@ -2230,6 +2230,54 @@ func TestFlagDefaultValue(t *testing.T) {
}
}

type flagValueTestCase struct {
name string
flag Flag
toParse []string
expect string
}

func TestFlagValue(t *testing.T) {
cases := []*flagValueTestCase{
&flagValueTestCase{
name: "stringSclice",
flag: &StringSliceFlag{Name: "flag", Value: NewStringSlice("default1", "default2")},
toParse: []string{"--flag", "parsed,parsed2", "--flag", "parsed3,parsed4"},
expect: `[parsed parsed2 parsed3 parsed4]`,
},
&flagValueTestCase{
name: "float64Sclice",
flag: &Float64SliceFlag{Name: "flag", Value: NewFloat64Slice(1.1, 2.2)},
toParse: []string{"--flag", "13.3,14.4", "--flag", "15.5,16.6"},
expect: `[]float64{13.3, 14.4, 15.5, 16.6}`,
},
&flagValueTestCase{
name: "int64Sclice",
flag: &Int64SliceFlag{Name: "flag", Value: NewInt64Slice(1, 2)},
toParse: []string{"--flag", "13,14", "--flag", "15,16"},
expect: `[]int64{13, 14, 15, 16}`,
},
&flagValueTestCase{
name: "intSclice",
flag: &IntSliceFlag{Name: "flag", Value: NewIntSlice(1, 2)},
toParse: []string{"--flag", "13,14", "--flag", "15,16"},
expect: `[]int{13, 14, 15, 16}`,
},
}
for i, v := range cases {
set := flag.NewFlagSet("test", 0)
set.SetOutput(ioutil.Discard)
_ = v.flag.Apply(set)
if err := set.Parse(v.toParse); err != nil {
t.Error(err)
}
f := set.Lookup("flag")
if got := f.Value.String(); got != v.expect {
t.Errorf("TestFlagValue %d-%s\nexpect:%s\ngot:%s", i, v.name, v.expect, got)
}
}
}

func TestTimestampFlagApply_WithDestination(t *testing.T) {
var destination Timestamp
expectedResult, _ := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")