Skip to content

Commit

Permalink
Support providing profile as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Jan 26, 2024
1 parent eacf945 commit 96bf4a5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Opt {
data_dir,
config_dir,
config_file,
profile,
mut profile,
command,
} = raw_opt;

Expand All @@ -85,15 +85,22 @@ impl Opt {
}
RawCommand::Edit => Command::Edit,
RawCommand::Remove { name } => Command::Remove { name },
RawCommand::Lock { update, reinstall } => {
RawCommand::Lock {
update,
reinstall,
profile: p,
} => {
profile = p.or(profile);
lock_mode = LockMode::from_lock_flags(update, reinstall);
Command::Lock
}
RawCommand::Source {
relock,
update,
reinstall,
profile: p,
} => {
profile = p.or(profile);
lock_mode = LockMode::from_source_flags(relock, update, reinstall);
Command::Source
}
Expand Down
8 changes: 8 additions & 0 deletions src/cli/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ pub enum RawCommand {
/// Reinstall all plugin sources.
#[clap(long, conflicts_with = "update")]
reinstall: bool,

/// The profile used for conditional plugins.
#[clap(value_name = "PROFILE", env = "SHELDON_PROFILE")]
profile: Option<String>,
},

/// Generate and print out the script.
Expand All @@ -115,6 +119,10 @@ pub enum RawCommand {
/// Reinstall all plugin sources (implies --relock).
#[clap(long, conflicts_with = "update")]
reinstall: bool,

/// The profile used for conditional plugins.
#[clap(value_name = "PROFILE", env = "SHELDON_PROFILE")]
profile: Option<String>,
},

/// Generate completions for the given shell.
Expand Down
5 changes: 4 additions & 1 deletion src/cli/testdata/raw_opt_lock_help.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Install the plugins sources and generate the lock file

Usage: sheldon lock [OPTIONS]
Usage: sheldon lock [OPTIONS] [PROFILE]

Arguments:
[PROFILE] The profile used for conditional plugins [env: SHELDON_PROFILE=]

Options:
--update Update all plugin sources
Expand Down
5 changes: 4 additions & 1 deletion src/cli/testdata/raw_opt_source_help.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Generate and print out the script

Usage: sheldon source [OPTIONS]
Usage: sheldon source [OPTIONS] [PROFILE]

Arguments:
[PROFILE] The profile used for conditional plugins [env: SHELDON_PROFILE=]

Options:
--relock Regenerate the lock file
Expand Down
7 changes: 5 additions & 2 deletions src/cli/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ fn raw_opt_no_options() {
profile: None,
command: RawCommand::Lock {
update: false,
reinstall: false
reinstall: false,
profile: None,
},
}
);
Expand All @@ -97,6 +98,7 @@ fn raw_opt_options() {
"--profile",
"profile",
"lock",
"profile2",
]),
RawOpt {
quiet: true,
Expand All @@ -109,7 +111,8 @@ fn raw_opt_options() {
profile: Some("profile".into()),
command: RawCommand::Lock {
update: false,
reinstall: false
reinstall: false,
profile: Some("profile2".into()),
},
}
);
Expand Down

0 comments on commit 96bf4a5

Please sign in to comment.