@@ -16,56 +16,78 @@ import (
1616)
1717
1818// CreateOptions specifies some options that are used when creating a config.
19+ //
20+ // Deprecated: this type was for internal use and will be removed in the next release.
1921type CreateOptions struct {
2022 Name string
2123 TemplateDriver string
2224 File string
2325 Labels opts.ListOpts
2426}
2527
26- func newConfigCreateCommand (dockerCli command.Cli ) * cobra.Command {
27- createOpts := CreateOptions {
28- Labels : opts .NewListOpts (opts .ValidateLabel ),
28+ // createOptions specifies some options that are used when creating a config.
29+ type createOptions struct {
30+ name string
31+ templateDriver string
32+ file string
33+ labels opts.ListOpts
34+ }
35+
36+ func newConfigCreateCommand (dockerCLI command.Cli ) * cobra.Command {
37+ createOpts := createOptions {
38+ labels : opts .NewListOpts (opts .ValidateLabel ),
2939 }
3040
3141 cmd := & cobra.Command {
3242 Use : "create [OPTIONS] CONFIG file|-" ,
3343 Short : "Create a config from a file or STDIN" ,
3444 Args : cli .ExactArgs (2 ),
3545 RunE : func (cmd * cobra.Command , args []string ) error {
36- createOpts .Name = args [0 ]
37- createOpts .File = args [1 ]
38- return RunConfigCreate (cmd .Context (), dockerCli , createOpts )
46+ createOpts .name = args [0 ]
47+ createOpts .file = args [1 ]
48+ return runCreate (cmd .Context (), dockerCLI , createOpts )
3949 },
4050 ValidArgsFunction : completion .NoComplete ,
4151 }
4252 flags := cmd .Flags ()
43- flags .VarP (& createOpts .Labels , "label" , "l" , "Config labels" )
44- flags .StringVar (& createOpts .TemplateDriver , "template-driver" , "" , "Template driver" )
45- flags .SetAnnotation ("template-driver" , "version" , []string {"1.37" })
53+ flags .VarP (& createOpts .labels , "label" , "l" , "Config labels" )
54+ flags .StringVar (& createOpts .templateDriver , "template-driver" , "" , "Template driver" )
55+ _ = flags .SetAnnotation ("template-driver" , "version" , []string {"1.37" })
4656
4757 return cmd
4858}
4959
5060// RunConfigCreate creates a config with the given options.
61+ //
62+ // Deprecated: this function was for internal use and will be removed in the next release.
5163func RunConfigCreate (ctx context.Context , dockerCLI command.Cli , options CreateOptions ) error {
64+ return runCreate (ctx , dockerCLI , createOptions {
65+ name : options .Name ,
66+ templateDriver : options .TemplateDriver ,
67+ file : options .File ,
68+ labels : options .Labels ,
69+ })
70+ }
71+
72+ // runCreate creates a config with the given options.
73+ func runCreate (ctx context.Context , dockerCLI command.Cli , options createOptions ) error {
5274 apiClient := dockerCLI .Client ()
5375
54- configData , err := readConfigData (dockerCLI .In (), options .File )
76+ configData , err := readConfigData (dockerCLI .In (), options .file )
5577 if err != nil {
56- return errors .Errorf ("Error reading content from %q: %v" , options .File , err )
78+ return errors .Errorf ("Error reading content from %q: %v" , options .file , err )
5779 }
5880
5981 spec := swarm.ConfigSpec {
6082 Annotations : swarm.Annotations {
61- Name : options .Name ,
62- Labels : opts .ConvertKVStringsToMap (options .Labels .GetSlice ()),
83+ Name : options .name ,
84+ Labels : opts .ConvertKVStringsToMap (options .labels .GetSlice ()),
6385 },
6486 Data : configData ,
6587 }
66- if options .TemplateDriver != "" {
88+ if options .templateDriver != "" {
6789 spec .Templating = & swarm.Driver {
68- Name : options .TemplateDriver ,
90+ Name : options .templateDriver ,
6991 }
7092 }
7193 r , err := apiClient .ConfigCreate (ctx , spec )
0 commit comments