Adds project-name as an optional argument for project initialization#1743
Adds project-name as an optional argument for project initialization#1743
Conversation
f93f446 to
31687d3
Compare
| exists := config.ProjectConfigExists() | ||
| exists, err := config.IsProjectDir(config.WorkingPath) | ||
| if err != nil { | ||
| return err | ||
| } |
There was a problem hiding this comment.
Alternative function we already had to check if the project config file exists in the directory or not. The prior version assumes that the process is already within the working directory, where the alternative lets us check if the file exists at the certain path.
2beaf76 to
c840b7f
Compare
| fmt.Printf(configReinitProjectConfigMsg+"\n", config.WorkingPath) | ||
| fmt.Printf(configReinitProjectConfigMsg, config.WorkingPath) | ||
| } else { | ||
| fmt.Printf(configInitProjectConfigMsg+"\n", config.WorkingPath) | ||
| fmt.Printf(configInitProjectConfigMsg, config.WorkingPath) | ||
| } |
There was a problem hiding this comment.
Just standardized the messages and the format strings and fixed a double vs single newline inconsistency.
| s.Run("invalid args", func() { | ||
| cmd := newAirflowInitCmd() | ||
| cmd.Flag("name").Value.Set("test-project-name") | ||
| args := []string{"invalid-arg"} | ||
|
|
||
| r, stdin := s.mockUserInput("y") | ||
|
|
||
| // Restore stdin right after the test. | ||
| defer func() { os.Stdin = stdin }() | ||
| os.Stdin = r | ||
| err := airflowInit(cmd, args) | ||
| s.ErrorIs(err, errProjectNameSpaces) | ||
| }) | ||
|
|
There was a problem hiding this comment.
This test is obsolete now that we accept a single positional argument. Cobra also will show help text if more than one positional argument is specified.
| fmt.Printf("Initializing Astro project\nPulling Airflow development files from Astronomer Certified Airflow Version %s\n", defaultImageTag) | ||
| } else { | ||
| fmt.Printf("Initializing Astro project\nPulling Airflow development files from Astro Runtime %s\n", defaultImageTag) |
There was a problem hiding this comment.
These messages are not necessary and duplicative. I've also updated the corresponding test for this output.
c840b7f to
f8b6b72
Compare
| errInvalidBothCustomImageandVersion = errors.New("you provided both a Custom image and a version. You have to provide only one of these to upgrade") //nolint | ||
|
|
||
| errConfigProjectName = errors.New("project name is invalid") | ||
| errProjectNameSpaces = errors.New("this project name is invalid, a project name cannot contain spaces. Try using '-' instead") |
There was a problem hiding this comment.
Obsolete error message. Cobra will show help text if more than one argument is specified.
8d649d8 to
69b2ea8
Compare
69b2ea8 to
4e82a74
Compare
neel-astro
left a comment
There was a problem hiding this comment.
Looks fine apart from one minor edge case :)
cmd/airflow.go
Outdated
| if len(args) > 0 { | ||
| projectName = args[0] | ||
| } |
There was a problem hiding this comment.
This might mean that if someone is trying astro dev init --name test project, would result in a project name as project when they might be looking for test project, should we at least warn and confirm if not error, when someone is setting both the flag and arg?
There was a problem hiding this comment.
Good catch. Updated the logic here to catch this case and throw an error.
There was a problem hiding this comment.
Also added a corresponding test.
| // If the project name is specified with the --name flag, | ||
| // it cannot be specified as a positional argument as well, so return an error. | ||
| if projectName != "" && len(args) > 0 { | ||
| return "", errConfigProjectNameSpecifiedTwice | ||
| } |
There was a problem hiding this comment.
@neel-astro added this case here to throw an error message if both the flag and positional argument are used.
I also separated all the new and existing "project name" logic into this new function to make the linter happy. :)
Description
This PR just allows the project name to be specified as an optional, positional argument. When used this way, we set the argument as the project name, and then additionally create a directory with the same name, and initialize a fresh project in that new directory. This change is purely additive, and existing commands and flags work the same as before.
Current
New
Example Usage
This change specifically:
Combined with #1728:
🎟 Issue(s)
Resolves to https://github.com/astronomer/astro/issues/25473
🧪 Functional Testing
📸 Screenshots
📋 Checklist
make testbefore taking out of draftmake lintbefore taking out of draft