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

Fixing passing --database-url as global cli arg #1201

Closed
wants to merge 6 commits into from

Conversation

weiznich
Copy link
Member

@weiznich weiznich commented Sep 25, 2017

--database-url is passed as global cli argument, this means it may be
not part of the current ArgMatches. To solve this we need to look recursivly in all current subcommands for the database-url

@sgrif
Copy link
Member

sgrif commented Sep 25, 2017

Does setting the global config accomplish the same thing? If not I think we should fix this in clap.

@weiznich
Copy link
Member Author

Does setting the global config accomplish the same thing? If not I think we should fix this in clap.

The documentation of global states explicitly the current behavior, so this seems to be desired or at least not fixable without changing larger parts of clap.

NOTE: Global arguments, when matched, only exist in the command's matches that they were matched to. For example, if you defined a --flag global argument in the top most parent command, but the user supplied the arguments top cmd1 cmd2 --flag only cmd2's ArgMatches would return true if tested for ArgMatches::is_present("flag").

@weiznich
Copy link
Member Author

weiznich commented Sep 25, 2017

There is also this issue on the clap repo, but setting this flag does not solve the problem…

Edit:
Setting this flag allows to simplify the fix, as we need now only to perform the recursive lookup.

--database-url is passed as global cli argument, this means it may be
not part of the current ArgMatches. To solve this we need to look recursivly
in all current subcommands for the database-url
@sgrif
Copy link
Member

sgrif commented Sep 25, 2017

Can you add a few test cases?

@weiznich
Copy link
Member Author

Something like the last commit?


#[test]
fn migration_run_runs_pending_migrations_custom_database_url_1() {
let p = project("migration_run").folder("migrations").build();
Copy link
Member

Choose a reason for hiding this comment

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

Every test case needs to have a unique project name.

@sgrif
Copy link
Member

sgrif commented Sep 25, 2017

The last commit is the sort of thing I had in mind, yes. However, those tests pass without your code changes

@sgrif
Copy link
Member

sgrif commented Sep 25, 2017

Based on some cursory testing, it looks like we should only need the .setting(AppSettings::PropagateGlobalValuesDown). However, that setting causes diesel --database-url=... database drop to work, but not diesel database --database-url=... drop. The addition of the database_url_from_cli function doesn't seem to affect it.

@weiznich
Copy link
Member Author

Based on some cursory testing, it looks like we should only need the .setting(AppSettings::PropagateGlobalValuesDown). However, that setting causes diesel --database-url=... database drop to work, but not diesel database --database-url=... drop. The addition of the database_url_from_cli function doesn't seem to affect it.

Executing target/debug/diesel migration run --migration-dir some/migrations/dir --database-url /tmp/test.db fails for me without the database_url_from_cli function.

Also this function may fix the issue with diesel --database-url=...

@weiznich
Copy link
Member Author

However, those tests pass without your code changes.

I've modified those tests to run without the DATABASE_URL environment variable. Now migration_run_runs_pending_migrations_custom_database_url_1 fails without the using database_url_from_cli

@sgrif
Copy link
Member

sgrif commented Sep 26, 2017

Can you add a note that we can remove that function once clap-rs/clap#978 is fixed?

@sgrif
Copy link
Member

sgrif commented Sep 26, 2017

You need to run rustfmt

@weiznich weiznich requested a review from a team October 12, 2017 08:11
weiznich added a commit to weiznich/diesel that referenced this pull request Nov 14, 2017
* 2 Testcases for --migration_dir
* Readd the tests from diesel-rs#1201 for --database_url
@weiznich
Copy link
Member Author

Fixed by #1304

@weiznich weiznich closed this Nov 27, 2017
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.

3 participants