Skip to content

Commit bd83445

Browse files
committed
Make the --database-url argument to cli global
This will ease testing as it means we can always pass it, and we don't have to worry about passing the argument to *every single subcommand*
1 parent 44e40bc commit bd83445

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

diesel_cli/src/main.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,25 @@ use std::{env, fs};
2222
use self::database_error::{DatabaseError, DatabaseResult};
2323

2424
fn main() {
25-
let database_arg = || Arg::with_name("DATABASE_URL")
25+
let database_arg = Arg::with_name("DATABASE_URL")
2626
.long("database-url")
2727
.help("Specifies the database URL to connect to. Falls back to \
2828
the DATABASE_URL environment variable if unspecified.")
29+
.global(true)
2930
.takes_value(true);
3031

3132
let migration_subcommand = SubCommand::with_name("migration")
3233
.setting(AppSettings::VersionlessSubcommands)
3334
.subcommand(
3435
SubCommand::with_name("run")
3536
.about("Runs all pending migrations")
36-
.arg(database_arg())
3737
).subcommand(
3838
SubCommand::with_name("revert")
3939
.about("Reverts the latest run migration")
40-
.arg(database_arg())
4140
).subcommand(
4241
SubCommand::with_name("redo")
4342
.about("Reverts and re-runs the latest migration. Useful \
4443
for testing that a migration can in fact be reverted.")
45-
.arg(database_arg())
4644
).subcommand(
4745
SubCommand::with_name("generate")
4846
.about("Generate a new migration with the given name, and \
@@ -55,26 +53,24 @@ fn main() {
5553

5654
let setup_subcommand = SubCommand::with_name("setup")
5755
.about("Creates the migrations directory, creates the database \
58-
specified in your DATABASE_URL, and runs existing migrations.")
59-
.arg(database_arg());
56+
specified in your DATABASE_URL, and runs existing migrations.");
6057

6158
let database_subcommand = SubCommand::with_name("database")
6259
.setting(AppSettings::VersionlessSubcommands)
6360
.subcommand(
6461
SubCommand::with_name("setup")
6562
.about("Creates the migrations directory, creates the database \
6663
specified in your DATABASE_URL, and runs existing migrations.")
67-
.arg(database_arg())
6864
).subcommand(
6965
SubCommand::with_name("reset")
7066
.about("Resets your database by dropping the database specified \
7167
in your DATABASE_URL and then running `diesel database setup`.")
72-
.arg(database_arg())
7368
).setting(AppSettings::SubcommandRequiredElseHelp);
7469

7570
let matches = App::new("diesel")
7671
.version(env!("CARGO_PKG_VERSION"))
7772
.setting(AppSettings::VersionlessSubcommands)
73+
.arg(database_arg)
7874
.subcommand(migration_subcommand)
7975
.subcommand(setup_subcommand)
8076
.subcommand(database_subcommand)

0 commit comments

Comments
 (0)