@@ -64,6 +64,7 @@ func createTemplateListCommand() *cobra.Command {
6464}
6565
6666func createTemplateAddCommand () * cobra.Command {
67+ var devcontainerName string
6768 cmd := & cobra.Command {
6869 Use : "add TEMPLATE_NAME" ,
6970 Short : "add devcontainer from template" ,
@@ -97,10 +98,12 @@ func createTemplateAddCommand() *cobra.Command {
9798 }
9899
99100 // by default the "name" in devcontainer.json is set to the name of the template
100- // override it here with the name of the containing folder
101- devcontainerName , err := devcontainers .GetDefaultDevcontainerNameForFolder (currentDirectory )
102- if err != nil {
103- return fmt .Errorf ("Error getting default devcontainer name: %s" , err )
101+ // override it here with the value passed in as --devcontainer-name (or the containing folder if not set)
102+ if devcontainerName == "" {
103+ devcontainerName , err = devcontainers .GetDefaultDevcontainerNameForFolder (currentDirectory )
104+ if err != nil {
105+ return fmt .Errorf ("Error getting default devcontainer name: %s" , err )
106+ }
104107 }
105108 devcontainerJsonPath := filepath .Join (currentDirectory , ".devcontainer/devcontainer.json" )
106109 err = devcontainers .SetDevcontainerName (devcontainerJsonPath , devcontainerName )
@@ -127,6 +130,7 @@ func createTemplateAddCommand() *cobra.Command {
127130 return names , cobra .ShellCompDirectiveNoFileComp
128131 },
129132 }
133+ cmd .Flags ().StringVar (& devcontainerName , "devcontainer-name" , "" , "Value to set the devcontainer.json name property to (default is folder name)" )
130134 return cmd
131135}
132136
0 commit comments