Skip to content

Ask for confirmation for sus project names #1051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2025
Merged

Conversation

lionello
Copy link
Member

Description

I had forgotten one dash and was confused why I didn't see any logs when I did defang tail -project-name defang. I figured it's not uncommon so I added a warning for it.

Checklist

  • I have performed a self-review of my code
  • I have added appropriate tests
  • I have updated the Defang CLI docs and/or README to reflect my changes, if necessary

Copy link
Member

@jordanstephens jordanstephens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this idea.

// Avoid common mistakes: using -p with a provider name instead of -P

// Avoid common mistakes
var doubleCheck bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we break this out now that it's getting more complicated?

func doubleCheck(cmd *cobra.Command, projectName string) {
	// Avoid common mistakes
	var doubleCheck bool
	var prov cliClient.ProviderID
	if prov.Set(projectName) == nil && !cmd.Flag("provider").Changed {
		// using -p with a provider name instead of -P
		term.Warnf("Project name %q looks like a provider name; did you mean to use -P=%s instead of -p?", projectName, projectName)
		doubleCheck = true
	} else if strings.HasPrefix(projectName, "roject-name") {
		// -project-name= instead of --project-name
		term.Warn("Did you mean to use --project-name instead of -project-name?")
		doubleCheck = true
	} else if strings.HasPrefix(projectName, "rovider") {
		// -provider= instead of --provider
		term.Warn("Did you mean to use --provider instead of -provider?")
		doubleCheck = true
	}

	if !nonInteractive && doubleCheck {
		var confirm bool
		err := survey.AskOne(&survey.Confirm{
			Message: "Continue with project: " + projectName + "?",
		}, &confirm, survey.WithStdio(term.DefaultTerm.Stdio()))
		track.Evt("ProjectNameConfirm", P("project", projectName), P("confirm", confirm), P("err", err))
		if err == nil && !confirm {
			os.Exit(1)
		}
	}
}

@lionello lionello merged commit 9837bc5 into main Mar 11, 2025
12 checks passed
@lionello lionello deleted the lio/confirm-project-name branch March 11, 2025 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants