Skip to content

src: Update dependencies and fix issue with usage message - #917

Merged
debarshiray merged 3 commits into
containers:mainfrom
martymichal:update-deps
Dec 17, 2021
Merged

debarshiray merged 3 commits into
containers:mainfrom
martymichal:update-deps

Conversation

@martymichal

@martymichal martymichal commented Nov 11, 2021 •

Copy link
Copy Markdown
Member

We haven't updated the dependencies of Toolbox since the rewrite in Go. There was no real need since our main target is Fedora that takes care of updating the different packages. But because of that we did not catch a regressions in Cobra (see the commit messages).

The dependency update has been done first for patch versions and then even for major versions. Both steps were filled with a call to go mod tidy.

Fixes #962

@martymichal martymichal added 6. Minor Change Should not cause breakage 3. Bugfix Fixes a bug 2. CLI Issue is related to the command line interface 3. Refinement Reduces technical debt of the codebase 2. Under The Hood Multiple areas of the app are influenced by this ticket labels Nov 11, 2021
@martymichal martymichal added this to the Release 0.1.0 milestone Nov 11, 2021
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@martymichal

Copy link
Copy Markdown
Member Author

recheck

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray

Copy link
Copy Markdown
Member

But because of that we did not catch a regressions in Cobra (see the commit messages).

Umm... I don't quite understand much from the commit messages.

Is there an actual regression in Cobra that we are addressing? But since we haven't updated the dependencies, how can it be a recent regression? Or are these just a periodic update of the dependencies?

@debarshiray debarshiray left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be easier to understand if the commit message included a clear example of the change in behaviour of Cobra. Like in spf13/cobra#1532

Comment thread test/system/002-help.bats Resolved
@debarshiray

Copy link
Copy Markdown
Member

But because of that we did not catch a regressions in Cobra (see the commit messages).

Umm... I don't quite understand much from the commit messages.

Is there an actual regression in Cobra that we are addressing? But since we
haven't updated the dependencies, how can it be a recent regression? Or are
these just a periodic update of the dependencies?

Ah, I see that it's a change in behaviour in newer Cobra versions that distributors might be using for their builds!

In that case, does the newer approach of using the templates also work with older versions of Cobra? I am asking because different versions of Fedora might have different versions of Cobra.

@martymichal

Copy link
Copy Markdown
Member Author

In that case, does the newer approach of using the templates also work with older versions of Cobra? I am asking because different versions of Fedora might have different versions of Cobra.

The template has been available from the very first version of Cobra, so yes.

martymichal added a commit to martymichal/toolbox that referenced this pull request Nov 16, 2021
- github.com/HarryMichal/go-version v1.0.0 => v1.0.1
- github.com/fsnotify/fsnotify v1.4.7 => v1.4.9
- github.com/godbus/dbus/v5 v5.0.3 => v5.0.6
- github.com/konsorten/go-windows-terminal-sequences v1.0.1 => v1.0.3
- github.com/magiconair/properties v1.8.0 => v1.8.5
- github.com/mattn/go-colorable v0.1.2 => v0.1.11
- github.com/mattn/go-isatty v0.0.8 => v0.0.14
- github.com/spf13/cast v1.3.0 => v1.3.1
- github.com/spf13/cobra v0.0.5 => v0.0.7
- github.com/spf13/pflag v1.0.3 => v1.0.5
- github.com/spf13/viper v1.3.2 => v1.4.0
- golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 => v0.0.0-20211115234514-b4de73f9ece8
- golang.org/x/sys v0.0.0-20190422165155-953cdadca894 => v0.0.0-20211113001501-0c823b97ae02
- golang.org/x/text v0.3.0 => v0.3.7
- gopkg.in/yaml.v2 v2.2.2 => v2.2.8

containers#917
martymichal added a commit to martymichal/toolbox that referenced this pull request Nov 16, 2021
- github.com/briandowns/spinner v1.10.0 => v1.16.0
- github.com/fatih/color v1.7.0 => v1.13.0
- github.com/fsnotify/fsnotify v1.4.9 => v1.5.1
- github.com/sirupsen/logrus v1.4.2 => v1.8.1
- github.com/spf13/cast v1.3.1 => v1.4.1
- github.com/spf13/cobra v0.0.7 => v1.2.1
- github.com/spf13/viper v1.4.0 => v1.9.0
- gopkg.in/ini.v1 v1.63.2 => v1.64.0
- gopkg.in/yaml.v2 v2.2.8 => v2.4.0

containers#917
martymichal added a commit to martymichal/toolbox that referenced this pull request Nov 16, 2021
In version 1.1.2 of Cobra has been included a change[0] that changes the
behaviour of how custom usage functions are printed. The change prepends
"Error: " to the text. This is not desired since the usage text is not
an error text.

Example of the wrong behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Error: Run 'toolbox --help' for usage.

Desired behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.

A workaround is to define a template string for the usage instead. The
template uses the templating language of Go[1]. See the default template
string in version 1.2.1[2].

Because the template is set only once, the executableBase needs to be
set before the template is applied. That required the move of
setUpGlobals() into init() of the cmd package. This is a better place
for the function call as init() is called earlier than Execute()[3].

Upstream issue: spf13/cobra#1532

[0] spf13/cobra#1044
[1] https://pkg.go.dev/text/template
[2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491
[3] https://golang.org/doc/effective_go#init

containers#917
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

martymichal added a commit to olivergs/toolbox that referenced this pull request Nov 21, 2021
- github.com/HarryMichal/go-version v1.0.0 => v1.0.1
- github.com/fsnotify/fsnotify v1.4.7 => v1.4.9
- github.com/godbus/dbus/v5 v5.0.3 => v5.0.6
- github.com/konsorten/go-windows-terminal-sequences v1.0.1 => v1.0.3
- github.com/magiconair/properties v1.8.0 => v1.8.5
- github.com/mattn/go-colorable v0.1.2 => v0.1.11
- github.com/mattn/go-isatty v0.0.8 => v0.0.14
- github.com/spf13/cast v1.3.0 => v1.3.1
- github.com/spf13/cobra v0.0.5 => v0.0.7
- github.com/spf13/pflag v1.0.3 => v1.0.5
- github.com/spf13/viper v1.3.2 => v1.4.0
- golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 => v0.0.0-20211115234514-b4de73f9ece8
- golang.org/x/sys v0.0.0-20190422165155-953cdadca894 => v0.0.0-20211113001501-0c823b97ae02
- golang.org/x/text v0.3.0 => v0.3.7
- gopkg.in/yaml.v2 v2.2.2 => v2.2.8

containers#917
martymichal added a commit to olivergs/toolbox that referenced this pull request Nov 21, 2021
- github.com/briandowns/spinner v1.10.0 => v1.16.0
- github.com/fatih/color v1.7.0 => v1.13.0
- github.com/fsnotify/fsnotify v1.4.9 => v1.5.1
- github.com/sirupsen/logrus v1.4.2 => v1.8.1
- github.com/spf13/cast v1.3.1 => v1.4.1
- github.com/spf13/cobra v0.0.7 => v1.2.1
- github.com/spf13/viper v1.4.0 => v1.9.0
- gopkg.in/ini.v1 v1.63.2 => v1.64.0
- gopkg.in/yaml.v2 v2.2.8 => v2.4.0

containers#917
martymichal added a commit to olivergs/toolbox that referenced this pull request Nov 21, 2021
In version 1.1.2 of Cobra has been included a change[0] that changes the
behaviour of how custom usage functions are printed. The change prepends
"Error: " to the text. This is not desired since the usage text is not
an error text.

Example of the wrong behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Error: Run 'toolbox --help' for usage.

Desired behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.

A workaround is to define a template string for the usage instead. The
template uses the templating language of Go[1]. See the default template
string in version 1.2.1[2].

Because the template is set only once, the executableBase needs to be
set before the template is applied. That required the move of
setUpGlobals() into init() of the cmd package. This is a better place
for the function call as init() is called earlier than Execute()[3].

Upstream issue: spf13/cobra#1532

[0] spf13/cobra#1044
[1] https://pkg.go.dev/text/template
[2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491
[3] https://golang.org/doc/effective_go#init

containers#917
@martymichal

Copy link
Copy Markdown
Member Author

@debarshiray?

@martymichal

Copy link
Copy Markdown
Member Author

This supersedes #775

martymichal added a commit to martymichal/toolbox that referenced this pull request Dec 15, 2021
- github.com/HarryMichal/go-version v1.0.0 => v1.0.1
- github.com/fsnotify/fsnotify v1.4.7 => v1.4.9
- github.com/godbus/dbus/v5 v5.0.3 => v5.0.6
- github.com/konsorten/go-windows-terminal-sequences v1.0.1 => v1.0.3
- github.com/magiconair/properties v1.8.0 => v1.8.5
- github.com/mattn/go-colorable v0.1.2 => v0.1.11
- github.com/mattn/go-isatty v0.0.8 => v0.0.14
- github.com/spf13/cast v1.3.0 => v1.3.1
- github.com/spf13/cobra v0.0.5 => v0.0.7
- github.com/spf13/pflag v1.0.3 => v1.0.5
- github.com/spf13/viper v1.3.2 => v1.4.0
- golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 => v0.0.0-20211115234514-b4de73f9ece8
- golang.org/x/sys v0.0.0-20190422165155-953cdadca894 => v0.0.0-20211113001501-0c823b97ae02
- golang.org/x/text v0.3.0 => v0.3.7
- gopkg.in/yaml.v2 v2.2.2 => v2.2.8

containers#917
martymichal added a commit to martymichal/toolbox that referenced this pull request Dec 15, 2021
- github.com/briandowns/spinner v1.10.0 => v1.16.0
- github.com/fatih/color v1.7.0 => v1.13.0
- github.com/fsnotify/fsnotify v1.4.9 => v1.5.1
- github.com/sirupsen/logrus v1.4.2 => v1.8.1
- github.com/spf13/cast v1.3.1 => v1.4.1
- github.com/spf13/cobra v0.0.7 => v1.2.1
- github.com/spf13/viper v1.4.0 => v1.9.0
- gopkg.in/ini.v1 v1.63.2 => v1.64.0
- gopkg.in/yaml.v2 v2.2.8 => v2.4.0

containers#917
martymichal added a commit to martymichal/toolbox that referenced this pull request Dec 15, 2021
In version 1.1.2 of Cobra has been included a change[0] that changes the
behaviour of how custom usage functions are printed. The change prepends
"Error: " to the text. This is not desired since the usage text is not
an error text.

Example of the wrong behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Error: Run 'toolbox --help' for usage.

Desired behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.

A workaround is to define a template string for the usage instead. The
template uses the templating language of Go[1]. See the default template
string in version 1.2.1[2].

Because the template is set only once, the executableBase needs to be
set before the template is applied. That required the move of
setUpGlobals() into init() of the cmd package. This is a better place
for the function call as init() is called earlier than Execute()[3].

Upstream issue: spf13/cobra#1532

[0] spf13/cobra#1044
[1] https://pkg.go.dev/text/template
[2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491
[3] https://golang.org/doc/effective_go#init

containers#917
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

martymichal added a commit to martymichal/toolbox that referenced this pull request Dec 16, 2021
In version 1.1.2 of Cobra has been included a change[0] that changes the
behaviour of how custom usage functions are printed. The change prepends
"Error: " to the text. This is not desired since the usage text is not
an error text.

Example of the wrong behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Error: Run 'toolbox --help' for usage.

Desired behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.

A workaround is to define a template string for the usage instead. The
template uses the templating language of Go[1]. See the default template
string in version 1.2.1[2].

Because the template is set only once, the executableBase needs to be
set before the template is applied. That required the move of
setUpGlobals() into init() of the cmd package. This is a better place
for the function call as init() is called earlier than Execute()[3].

Upstream issue: spf13/cobra#1532

[0] spf13/cobra#1044
[1] https://pkg.go.dev/text/template
[2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491
[3] https://golang.org/doc/effective_go#init

containers#917
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray debarshiray left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. One quick comment:

Comment thread src/go.mod Resolved
Comment thread src/go.mod Resolved
Comment thread src/go.mod Resolved
- github.com/HarryMichal/go-version v1.0.0 => v1.0.1
- github.com/fsnotify/fsnotify v1.4.7 => v1.4.9
- github.com/godbus/dbus/v5 v5.0.3 => v5.0.6
- github.com/mattn/go-isatty v0.0.8 => v0.0.14
- github.com/spf13/cobra v0.0.5 => v0.0.7
- github.com/spf13/viper v1.3.2 => v1.4.0
- golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 => v0.0.0-20211115234514-b4de73f9ece8
- golang.org/x/sys v0.0.0-20190422165155-953cdadca894 => v0.0.0-20211113001501-0c823b97ae02

containers#917
@debarshiray

Copy link
Copy Markdown
Member

Some more observations ...

As far as I understand, the wrong behaviour isn't this, as mentioned in the commit message:

$ toolbox --foo
Error: unknown flag: --foo
Error: Run 'toolbox --help' for usage.

It's actually this:

$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.Error: Run 'toolbox --help' for usage.

ie., the usage string gets strangely duplicated, with an Error: prefix in the middle.

We could have avoided the duplication by not printing the text ourselves, if it wasn't for the extra prefix, etc.. These are details that we don't have to explain in detail, but the example is important. A wrong example will confuse people even more because it won't match their observation.

Secondly, we should bump the dependencies with go get -u after working around the Cobra issue. Otherwise it will break git bisect.

Comment thread src/go.mod
github.com/mattn/go-isatty v0.0.8
github.com/fsnotify/fsnotify v1.4.9
github.com/godbus/dbus/v5 v5.0.6
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to highlight the changes in the indirect dependencies in the commit message. There are just too many of those and they keep coming and going. It's better to only highlight our direct dependencies in the commit message, unless there's one that we really need to be careful about.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

In version 1.1.2 of Cobra has been included a change[0] that changes
how custom usage functions are handled.

Example of the wrong behaviour:
$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.Error: Run 'toolbox --help' for usage.

Desired behaviour:
$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.

A workaround is to define a template string for the usage instead. The
template uses the templating language of Go[1]. See the default
template string in version 1.2.1[2].

Because the template is set only once, the executableBase needs to be
set before the template is applied. That required the move of
setUpGlobals() into init() of the cmd package. This is a better place
for the function call as init() is called earlier than Execute()[3].

Upstream issue: spf13/cobra#1532

[0] spf13/cobra#1044
[1] https://pkg.go.dev/text/template
[2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491
[3] https://golang.org/doc/effective_go#init

containers#917
- github.com/acobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249 => v0.1.0
- github.com/briandowns/spinner v1.10.0 => v1.17.0
- github.com/fsnotify/fsnotify v1.4.9 => v1.5.1
- github.com/sirupsen/logrus v1.4.2 => v1.8.1
- github.com/spf13/cobra v0.0.7 => v1.3.0
- github.com/spf13/viper v1.4.0 => v1.10.1
- golang.org/x/crypto v0.0.0-20211115234514-b4de73f9ece8 => v0.0.0-20211215153901-e495a2d5b3d3
- golang.org/x/sys v0.0.0-20211113001501-0c823b97ae02 => v0.0.0-20211216021012-1d35b9e2eb4e

containers#917
@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray

Copy link
Copy Markdown
Member

recheck

martymichal added a commit to martymichal/toolbox that referenced this pull request Dec 17, 2021
- github.com/HarryMichal/go-version v1.0.0 => v1.0.1
- github.com/fsnotify/fsnotify v1.4.7 => v1.4.9
- github.com/godbus/dbus/v5 v5.0.3 => v5.0.6
- github.com/mattn/go-isatty v0.0.8 => v0.0.14
- github.com/spf13/cobra v0.0.5 => v0.0.7
- github.com/spf13/viper v1.3.2 => v1.4.0
- golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 => v0.0.0-20211215153901-e495a2d5b3d3
- golang.org/x/sys v0.0.0-20190422165155-953cdadca894 => v0.0.0-20211216021012-1d35b9e2eb4e

containers#917
martymichal added a commit to martymichal/toolbox that referenced this pull request Dec 17, 2021
In version 1.1.2 of Cobra has been included a change[0] that changes
how custom usage functions are handled.

Example of the wrong behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.Error: Run 'toolbox --help' for usage.

Desired behaviour:

$ toolbox --foo
Error: unknown flag: --foo
Run 'toolbox --help' for usage.

A workaround is to define a template string for the usage instead. The
template uses the templating language of Go[1]. See the default template
string in version 1.2.1[2].

Because the template is set only once, the executableBase needs to be
set before the template is applied. That required the move of
setUpGlobals() into init() of the cmd package. This is a better place
for the function call as init() is called earlier than Execute()[3].

Upstream issue: spf13/cobra#1532

[0] spf13/cobra#1044
[1] https://pkg.go.dev/text/template
[2] https://github.com/spf13/cobra/blob/v1.2.1/command.go#L491
[3] https://golang.org/doc/effective_go#init

containers#917
martymichal added a commit to martymichal/toolbox that referenced this pull request Dec 17, 2021
- github.com/acobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249 => v0.1.0
- github.com/briandowns/spinner v1.10.0 => v1.17.0
- github.com/fsnotify/fsnotify v1.4.9 => v1.5.1
- github.com/sirupsen/logrus v1.4.2 => v1.8.1
- github.com/spf13/cobra v0.0.7 => v1.3.0
- github.com/spf13/viper v1.4.0 => v1.10.1
- golang.org/x/crypto v0.0.0-20211115234514-b4de73f9ece8 => v0.0.0-20211215153901-e495a2d5b3d3
- golang.org/x/sys v0.0.0-20211113001501-0c823b97ae02 => v0.0.0-20211216021012-1d35b9e2eb4e

containers#917
@debarshiray

Copy link
Copy Markdown
Member

Wow! Software Factory is really struggling today.

@softwarefactory-delete-me

Copy link
Copy Markdown

Build failed.

@debarshiray
debarshiray merged commit 73c53a3 into containers:main Dec 17, 2021
@martymichal
martymichal deleted the update-deps branch December 18, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. CLI Issue is related to the command line interface 2. Under The Hood Multiple areas of the app are influenced by this ticket 3. Bugfix Fixes a bug 3. Refinement Reduces technical debt of the codebase 6. Minor Change Should not cause breakage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Doubled usage line

2 participants