cmd/new+init: added instructions for new + fix for init arg

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-05-26 17:41:37 +02:00
parent 1f4bbc53ad
commit 97be7b917a
2 changed files with 9 additions and 3 deletions

View File

@ -12,7 +12,7 @@ import (
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize a new empty workspace",
Args: cobra.MaximumNArgs(1),
Args: cobra.NoArgs,
PreRun: func(cmd *cobra.Command, args []string) {
// Fix Viper bug for duplicate flags:
// https://github.com/spf13/viper/issues/233

View File

@ -1,6 +1,8 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.dagger.io/dagger/cmd/dagger/cmd/common"
@ -8,7 +10,7 @@ import (
)
var newCmd = &cobra.Command{
Use: "new",
Use: "new <NAME>",
Short: "Create a new empty environment",
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
@ -30,9 +32,13 @@ var newCmd = &cobra.Command{
Msg("cannot use option -e,--environment for this command")
}
name := args[0]
if _, err := workspace.Create(ctx, name); err != nil {
ws, err := workspace.Create(ctx, name)
if err != nil {
lg.Fatal().Err(err).Msg("failed to create environment")
}
lg.Info().Str("name", name).Msg("created new empty environment")
lg.Info().Str("name", name).Msg(fmt.Sprintf("to add code to the plan, copy or create cue files under: %s", ws.Plan))
},
}