Add support for experimental Cli configuration
Allow to mark some commands and flags experimental on cli (i.e. not depending to the state of the daemon). This will allow more flexibility on experimentation with the cli. Marking `docker trust` as cli experimental as it is documented so. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
@ -193,6 +193,7 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
|
||||
|
||||
type versionDetails interface {
|
||||
Client() client.APIClient
|
||||
ClientInfo() command.ClientInfo
|
||||
ServerInfo() command.ServerInfo
|
||||
}
|
||||
|
||||
@ -200,6 +201,7 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
|
||||
clientVersion := details.Client().ClientVersion()
|
||||
osType := details.ServerInfo().OSType
|
||||
hasExperimental := details.ServerInfo().HasExperimental
|
||||
hasExperimentalCLI := details.ClientInfo().HasExperimental
|
||||
|
||||
cmd.Flags().VisitAll(func(f *pflag.Flag) {
|
||||
// hide experimental flags
|
||||
@ -208,6 +210,11 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
|
||||
f.Hidden = true
|
||||
}
|
||||
}
|
||||
if !hasExperimentalCLI {
|
||||
if _, ok := f.Annotations["experimentalCLI"]; ok {
|
||||
f.Hidden = true
|
||||
}
|
||||
}
|
||||
|
||||
// hide flags not supported by the server
|
||||
if !isOSTypeSupported(f, osType) || !isVersionSupported(f, clientVersion) {
|
||||
@ -222,6 +229,11 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
|
||||
subcmd.Hidden = true
|
||||
}
|
||||
}
|
||||
if !hasExperimentalCLI {
|
||||
if _, ok := subcmd.Annotations["experimentalCLI"]; ok {
|
||||
subcmd.Hidden = true
|
||||
}
|
||||
}
|
||||
|
||||
// hide subcommands not supported by the server
|
||||
if subcmdVersion, ok := subcmd.Annotations["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) {
|
||||
@ -234,6 +246,7 @@ func isSupported(cmd *cobra.Command, details versionDetails) error {
|
||||
clientVersion := details.Client().ClientVersion()
|
||||
osType := details.ServerInfo().OSType
|
||||
hasExperimental := details.ServerInfo().HasExperimental
|
||||
hasExperimentalCLI := details.ClientInfo().HasExperimental
|
||||
|
||||
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
|
||||
for curr := cmd; curr != nil; curr = curr.Parent() {
|
||||
@ -243,6 +256,9 @@ func isSupported(cmd *cobra.Command, details versionDetails) error {
|
||||
if _, ok := curr.Annotations["experimental"]; ok && !hasExperimental {
|
||||
return fmt.Errorf("%s is only supported on a Docker daemon with experimental features enabled", cmd.CommandPath())
|
||||
}
|
||||
if _, ok := curr.Annotations["experimentalCLI"]; ok && !hasExperimentalCLI {
|
||||
return fmt.Errorf("%s is only supported when experimental cli features are enabled", cmd.CommandPath())
|
||||
}
|
||||
}
|
||||
|
||||
errs := []string{}
|
||||
@ -260,6 +276,9 @@ func isSupported(cmd *cobra.Command, details versionDetails) error {
|
||||
if _, ok := f.Annotations["experimental"]; ok && !hasExperimental {
|
||||
errs = append(errs, fmt.Sprintf("\"--%s\" is only supported on a Docker daemon with experimental features enabled", f.Name))
|
||||
}
|
||||
if _, ok := f.Annotations["experimentalCLI"]; ok && !hasExperimentalCLI {
|
||||
errs = append(errs, fmt.Sprintf("\"--%s\" is only supported when experimental cli features are enabled", f.Name))
|
||||
}
|
||||
}
|
||||
})
|
||||
if len(errs) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user