cmd/new: implemented optional arg to specify name, forbid usage of -d option
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
47b16a1d1b
commit
b9b195b70f
@ -17,7 +17,7 @@ import (
|
|||||||
var newCmd = &cobra.Command{
|
var newCmd = &cobra.Command{
|
||||||
Use: "new",
|
Use: "new",
|
||||||
Short: "Create a new deployment",
|
Short: "Create a new deployment",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.MaximumNArgs(1),
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
// Fix Viper bug for duplicate flags:
|
// Fix Viper bug for duplicate flags:
|
||||||
// https://github.com/spf13/viper/issues/233
|
// https://github.com/spf13/viper/issues/233
|
||||||
@ -33,8 +33,21 @@ var newCmd = &cobra.Command{
|
|||||||
lg.Fatal().Err(err).Msg("failed to load store")
|
lg.Fatal().Err(err).Msg("failed to load store")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if viper.GetString("deployment") != "" {
|
||||||
|
lg.
|
||||||
|
Fatal().
|
||||||
|
Msg("cannot use option -d,--deployment for this command")
|
||||||
|
}
|
||||||
|
|
||||||
|
name := ""
|
||||||
|
if len(args) > 0 {
|
||||||
|
name = args[0]
|
||||||
|
} else {
|
||||||
|
name = getNewDeploymentName(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
st := &dagger.DeploymentState{
|
st := &dagger.DeploymentState{
|
||||||
Name: getNewDeploymentName(ctx),
|
Name: name,
|
||||||
PlanSource: getPlanSource(ctx),
|
PlanSource: getPlanSource(ctx),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +78,6 @@ var newCmd = &cobra.Command{
|
|||||||
func getNewDeploymentName(ctx context.Context) string {
|
func getNewDeploymentName(ctx context.Context) string {
|
||||||
lg := log.Ctx(ctx)
|
lg := log.Ctx(ctx)
|
||||||
|
|
||||||
deploymentName := viper.GetString("name")
|
|
||||||
if deploymentName != "" {
|
|
||||||
return deploymentName
|
|
||||||
}
|
|
||||||
|
|
||||||
workDir, err := os.Getwd()
|
workDir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
lg.
|
lg.
|
||||||
@ -99,7 +107,6 @@ func getPlanSource(ctx context.Context) dagger.Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
newCmd.Flags().StringP("name", "n", "", "Specify a deployment name")
|
|
||||||
newCmd.Flags().BoolP("up", "u", false, "Bring the deployment online")
|
newCmd.Flags().BoolP("up", "u", false, "Bring the deployment online")
|
||||||
|
|
||||||
newCmd.Flags().String("plan-dir", "", "Load plan from a local directory")
|
newCmd.Flags().String("plan-dir", "", "Load plan from a local directory")
|
||||||
|
Reference in New Issue
Block a user