Add upstream patch fixing doubled error messages
This commit is contained in:
parent
9bebde5bb6
commit
3a1aa2f691
@ -0,0 +1,95 @@
|
|||||||
|
From e598e2160323b63310ad7b6def723eb1f8767f90 Mon Sep 17 00:00:00 2001
|
||||||
|
From: =?UTF-8?q?Ond=C5=99ej=20M=C3=ADchal?= <harrymichal@seznam.cz>
|
||||||
|
Date: Thu, 11 Nov 2021 18:18:52 +0200
|
||||||
|
Subject: [PATCH 02/13] cmd/root: Work around Cobra 1.1.2's handling of usage
|
||||||
|
functions
|
||||||
|
|
||||||
|
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: https://github.com/spf13/cobra/issues/1532
|
||||||
|
|
||||||
|
[0] https://github.com/spf13/cobra/pull/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
|
||||||
|
|
||||||
|
https://github.com/containers/toolbox/pull/917
|
||||||
|
---
|
||||||
|
src/cmd/root.go | 20 ++++++++------------
|
||||||
|
1 file changed, 8 insertions(+), 12 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/cmd/root.go b/src/cmd/root.go
|
||||||
|
index eb0622f..ad0753b 100644
|
||||||
|
--- a/src/cmd/root.go
|
||||||
|
+++ b/src/cmd/root.go
|
||||||
|
@@ -62,11 +62,6 @@ var (
|
||||||
|
)
|
||||||
|
|
||||||
|
func Execute() {
|
||||||
|
- if err := setUpGlobals(); err != nil {
|
||||||
|
- fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||||
|
- os.Exit(1)
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
if err := rootCmd.Execute(); err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
@@ -75,6 +70,11 @@ func Execute() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
+ if err := setUpGlobals(); err != nil {
|
||||||
|
+ fmt.Fprintf(os.Stderr, "Error: %s\n", err)
|
||||||
|
+ os.Exit(1)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
persistentFlags := rootCmd.PersistentFlags()
|
||||||
|
|
||||||
|
persistentFlags.BoolVarP(&rootFlags.assumeYes,
|
||||||
|
@@ -96,7 +96,9 @@ func init() {
|
||||||
|
persistentFlags.CountVarP(&rootFlags.verbose, "verbose", "v", "Set log-level to 'debug'")
|
||||||
|
|
||||||
|
rootCmd.SetHelpFunc(rootHelp)
|
||||||
|
- rootCmd.SetUsageFunc(rootUsage)
|
||||||
|
+
|
||||||
|
+ usageTemplate := fmt.Sprintf("Run '%s --help' for usage.", executableBase)
|
||||||
|
+ rootCmd.SetUsageTemplate(usageTemplate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func preRun(cmd *cobra.Command, args []string) error {
|
||||||
|
@@ -188,12 +190,6 @@ func rootRun(cmd *cobra.Command, args []string) error {
|
||||||
|
return rootRunImpl(cmd, args)
|
||||||
|
}
|
||||||
|
|
||||||
|
-func rootUsage(cmd *cobra.Command) error {
|
||||||
|
- err := fmt.Errorf("Run '%s --help' for usage.", executableBase)
|
||||||
|
- fmt.Fprintf(os.Stderr, "%s", err)
|
||||||
|
- return err
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
func migrate() error {
|
||||||
|
logrus.Debug("Migrating to newer Podman")
|
||||||
|
|
||||||
|
--
|
||||||
|
2.34.1
|
||||||
|
|
@ -6,7 +6,7 @@ Version: 0.0.99.3
|
|||||||
%global goipath github.com/containers/%{name}
|
%global goipath github.com/containers/%{name}
|
||||||
%gometa
|
%gometa
|
||||||
|
|
||||||
Release: 2%{?dist}
|
Release: 3%{?dist}
|
||||||
Summary: Tool for containerized command line environments on Linux
|
Summary: Tool for containerized command line environments on Linux
|
||||||
|
|
||||||
License: ASL 2.0
|
License: ASL 2.0
|
||||||
@ -17,6 +17,7 @@ Source0: https://github.com/containers/%{name}/releases/download/%{version
|
|||||||
Patch100: toolbox-Don-t-use-Go-s-semantic-import-versioning.patch
|
Patch100: toolbox-Don-t-use-Go-s-semantic-import-versioning.patch
|
||||||
Patch101: toolbox-Make-the-build-flags-match-Fedora-s-gobuild.patch
|
Patch101: toolbox-Make-the-build-flags-match-Fedora-s-gobuild.patch
|
||||||
Patch102: toolbox-Make-the-build-flags-match-Fedora-s-gobuild-for-PPC64.patch
|
Patch102: toolbox-Make-the-build-flags-match-Fedora-s-gobuild-for-PPC64.patch
|
||||||
|
Patch103: toolbox-cmd-root-Work-around-Cobra-1.1.2-s-handling-of-usage.patch
|
||||||
|
|
||||||
BuildRequires: ShellCheck
|
BuildRequires: ShellCheck
|
||||||
BuildRequires: golang >= 1.13
|
BuildRequires: golang >= 1.13
|
||||||
@ -144,6 +145,8 @@ The %{name}-tests package contains system tests for %{name}.
|
|||||||
%patch102 -p1
|
%patch102 -p1
|
||||||
%endif
|
%endif
|
||||||
|
|
||||||
|
%patch103 -p1
|
||||||
|
|
||||||
%gomkdir
|
%gomkdir
|
||||||
|
|
||||||
|
|
||||||
@ -185,6 +188,9 @@ ln -s src/pkg pkg
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Sun Jan 09 2022 Ondřej Míchal <harrymichal@fedoraproject.org> - 0.0.99.3-3
|
||||||
|
- Add upstream patch fixing doubled error messages
|
||||||
|
|
||||||
* Fri Dec 10 2021 Debarshi Ray <rishi@fedoraproject.org> - 0.0.99.3-2
|
* Fri Dec 10 2021 Debarshi Ray <rishi@fedoraproject.org> - 0.0.99.3-2
|
||||||
- BuildRequire only systemd-rpm-macros as recommended by the Fedora packaging
|
- BuildRequire only systemd-rpm-macros as recommended by the Fedora packaging
|
||||||
guidelines
|
guidelines
|
||||||
|
Loading…
Reference in New Issue
Block a user