-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add variable for global flags to runlabel #2905
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,12 @@ import ( | |
|
||
"github.com/BurntSushi/toml" | ||
"github.com/containers/image/types" | ||
"github.com/containers/libpod/cmd/podman/cliconfig" | ||
"github.com/containers/storage" | ||
"github.com/containers/storage/pkg/idtools" | ||
"github.com/opencontainers/image-spec/specs-go/v1" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/pflag" | ||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
|
@@ -252,3 +254,32 @@ func ParseInputTime(inputTime string) (time.Time, error) { | |
} | ||
return time.Now().Add(-duration), nil | ||
} | ||
|
||
// GetGlobalOpts checks all global flags and generates the command string | ||
func GetGlobalOpts(c *cliconfig.RunlabelValues) string { | ||
globalFlags := map[string]bool{ | ||
"cgroup-manager": true, "cni-config-dir": true, "conmon": true, "default-mounts-file": true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate PR, but could you move this to main_local.go
That way if a user adds a global flag, it is much more likely they will do the right thing. |
||
"hooks-dir": true, "namespace": true, "root": true, "runroot": true, | ||
"runtime": true, "storage-driver": true, "storage-opt": true, "syslog": true, | ||
"trace": true, "network-cmd-path": true, "config": true, "cpu-profile": true, | ||
"log-level": true, "tmpdir": true} | ||
const stringSliceType string = "stringSlice" | ||
|
||
var optsCommand []string | ||
c.PodmanCommand.Command.Flags().VisitAll(func(f *pflag.Flag) { | ||
if !f.Changed { | ||
return | ||
} | ||
if _, exist := globalFlags[f.Name]; exist { | ||
if f.Value.Type() == stringSliceType { | ||
flagValue := strings.TrimSuffix(strings.TrimPrefix(f.Value.String(), "["), "]") | ||
for _, value := range strings.Split(flagValue, ",") { | ||
optsCommand = append(optsCommand, fmt.Sprintf("--%s %s", f.Name, value)) | ||
} | ||
} else { | ||
optsCommand = append(optsCommand, fmt.Sprintf("--%s %s", f.Name, f.Value.String())) | ||
} | ||
} | ||
}) | ||
return strings.Join(optsCommand, " ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can somehow pull the names of the global flags straight out of Cobra - @baude you know if there's a way to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found FlagSet.VisitAll() for all flags, not just for global flags...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. This could be painful if we add more global flags, but no helping that, I suppose.