Skip to content
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

Fix command line argument handling for slice configuration parameters #299

Merged
merged 5 commits into from
Jul 2, 2022

Conversation

the
Copy link
Contributor

@the the commented Jul 1, 2022

It seems slice configuration parameters such as ExcludeDir cannot be set correctly with command line arguments (nor override default config). The test for --build.exclude_regex only passes because the test value corresponds with the default value (set in defaultConfig), it's not actually set by the parameter in the test.

I propose to treat the command line arguments for such config parameters as comma separated strings. Setting a value would work as e.g. --build.exclude_dir "templates,build".

@xiantang
Copy link
Collaborator

xiantang commented Jul 1, 2022

thx let me take a look

@xiantang
Copy link
Collaborator

xiantang commented Jul 1, 2022

ci not pass

@xiantang xiantang self-requested a review July 1, 2022 15:57
@@ -103,9 +103,9 @@ func TestConfigRuntimeArgs(t *testing.T) {
},
{
name: "check exclude_regex",
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add the test case which is empty slice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm what would you expect in that case, the default values ore empty slice? It seems currently it keeps the default values (I didn't think of this case before), but I'd rather expect to set it to empty.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer set it to empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I think it isn't that straightforward. Before a value is set there's a check for nil and empty string https:/cosmtrek/air/blob/master/runner/config.go#L324. If I only keep the nil check it would work (with an additional change in util.go to explicitly set an empty slice), but that will override all the default values because arguments that are not explicitly set seem to end up as empty strings instead of nil. Do you think it would be easy to adjust that non-set arguments would be nil instead of empty strings? I don't know the code base well enough yet and I have not so much experience with the flag package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I see correctly it's only possible to define string variable flags with a string as default value (not a pointer, thus impossible to set nil as default value).

See also here https:/cosmtrek/air/blob/master/runner/flag.go#L12.

Copy link
Collaborator

@xiantang xiantang Jul 2, 2022

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your support. I cherry-picked all 3 commits.

@xiantang
Copy link
Collaborator

xiantang commented Jul 1, 2022

@the use comma to split string as slice is a good idea! plz fix the lint, and add the test case which include empty string, and seems should add more description in README.

after that, I will merge this PR. thanks

@the
Copy link
Contributor Author

the commented Jul 1, 2022

ci not pass

I'm puzzled about the errors: main.go:6:2: undefined: Println. I haven't even changed that file and I don't see anything wrong with the fmt.Println's in main 🤔. Do you have any idea?

@codecov
Copy link

codecov bot commented Jul 1, 2022

Codecov Report

Merging #299 (5af6212) into master (664ec37) will increase coverage by 0.61%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #299      +/-   ##
==========================================
+ Coverage   66.29%   66.91%   +0.61%     
==========================================
  Files           6        7       +1     
  Lines         905      943      +38     
==========================================
+ Hits          600      631      +31     
- Misses        241      246       +5     
- Partials       64       66       +2     
Impacted Files Coverage Δ
runner/config.go 70.00% <100.00%> (ø)
runner/flag.go 100.00% <100.00%> (ø)
runner/util.go 69.54% <100.00%> (+1.49%) ⬆️
runner/util_darwin.go 66.66% <0.00%> (ø)
runner/engine.go 62.30% <0.00%> (+0.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 664ec37...5af6212. Read the comment docs.

@xiantang
Copy link
Collaborator

xiantang commented Jul 1, 2022

ci not pass

I'm puzzled about the errors: main.go:6:2: undefined: Println. I haven't even changed that file and I don't see anything wrong with the fmt.Println's in main 🤔. Do you have any idea?

I have rerunned the failed test, It's passed. the failed pipeline seems not relate with this version. ignore it.

@the
Copy link
Contributor Author

the commented Jul 1, 2022

@the use comma to split string as slice is a good idea! plz fix the lint, and add the test case which include empty string, and seems should add more description in README.

after that, I will merge this PR. thanks

I added a small note in the README.

@@ -30,6 +30,10 @@ Air 是为 Go 应用开发设计的另外一个热重载的命令行工具。只

`air --build.cmd "go build -o bin/api cmd/run.go" --build.bin "./bin/api"`

对于以列表形式输入的参数,使用逗号来分隔项目:
Copy link
Collaborator

Choose a reason for hiding this comment

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

great!

@xiantang
Copy link
Collaborator

xiantang commented Jul 2, 2022

#300

@xiantang xiantang merged commit b878e3c into air-verse:master Jul 2, 2022
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