Skip to content

Commit

Permalink
Support profile as argument
Browse files Browse the repository at this point in the history
You can now specify a profile as an argument to the `lock` and `source`
commands. This can be more readable than using environment variables
or the `--profile` option.

Example:

```
sheldon source my-profile
```
  • Loading branch information
rossmacarthur committed Aug 25, 2024
1 parent f9842b1 commit 14d4f0d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 8 deletions.
4 changes: 2 additions & 2 deletions completions/sheldon.bash
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ _sheldon() {
return 0
;;
sheldon__lock)
opts="-h --update --reinstall --help"
opts="-h --update --reinstall --help [PROFILE]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down Expand Up @@ -225,7 +225,7 @@ _sheldon() {
return 0
;;
sheldon__source)
opts="-h --relock --update --reinstall --help"
opts="-h --relock --update --reinstall --help [PROFILE]"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
2 changes: 2 additions & 0 deletions completions/sheldon.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ _arguments "${_arguments_options[@]}" : \
'(--update)--reinstall[Reinstall all plugin sources]' \
'-h[Print help]' \
'--help[Print help]' \
'::profile -- The profile used for conditional plugins:' \
&& ret=0
;;
(source)
Expand All @@ -94,6 +95,7 @@ _arguments "${_arguments_options[@]}" : \
'(--update)--reinstall[Reinstall all plugin sources (implies --relock)]' \
'-h[Print help]' \
'--help[Print help]' \
'::profile -- The profile used for conditional plugins:' \
&& ret=0
;;
(completions)
Expand Down
11 changes: 9 additions & 2 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Opt {
data_dir,
config_dir,
config_file,
profile,
mut profile,
command,
} = raw_opt;

Expand All @@ -84,15 +84,22 @@ impl Opt {
}
RawCommand::Edit => Command::Edit,
RawCommand::Remove { name } => Command::Remove { name },
RawCommand::Lock { update, reinstall } => {
RawCommand::Lock {
update,
reinstall,
profile: profile_arg,
} => {
profile = profile_arg.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 @@ -101,6 +101,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 @@ -116,6 +120,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 14d4f0d

Please sign in to comment.