Skip to content

Commit 5a8254d

Browse files
committed
Support updating of plugins
- Adds a new `--update` option to both the `lock` and `source` commands. - Updating Git sources will now fetch the remote and recheckout the configured reference. - Updating remote sources will redownload them (same as `--reinstall`). - Fixes some issues with changing `branch`, `tag`, and `rev` fields in plugin configuration. Sheldon now correctly checks the new reference out and will try fetch from the remote if the reference is missing locally.
1 parent 57b3375 commit 5a8254d

6 files changed

Lines changed: 267 additions & 117 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ are all okay. It will always regenerate the lock file.
176176
sheldon lock
177177
```
178178

179+
To update all plugin sources you can use the `--update` flag.
180+
181+
```sh
182+
sheldon lock --update
183+
```
184+
179185
To force a reinstall of all plugin sources you can use the `--reinstall` flag.
180186

181187
```sh

src/cli.rs

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use url::Url;
1111

1212
use crate::{
1313
config::{GistRepository, GitHubRepository, GitProtocol, GitReference, RawPlugin, Shell},
14-
context::Settings,
14+
context::{LockMode, Settings},
1515
edit::Plugin,
1616
log::{Output, Verbosity},
1717
};
@@ -119,8 +119,12 @@ enum RawCommand {
119119
/// Install the plugins sources and generate the lock file.
120120
#[structopt(help_message = HELP_MESSAGE)]
121121
Lock {
122-
/// Reinstall all plugin sources.
122+
/// Update all plugin sources.
123123
#[structopt(long)]
124+
update: bool,
125+
126+
/// Reinstall all plugin sources.
127+
#[structopt(long, conflicts_with = "update")]
124128
reinstall: bool,
125129
},
126130

@@ -130,8 +134,13 @@ enum RawCommand {
130134
/// Regenerate the lock file.
131135
#[structopt(long)]
132136
relock: bool,
133-
/// Reinstall all plugin sources (implies --relock).
137+
138+
/// Update all plugin sources (implies --relock).
134139
#[structopt(long)]
140+
update: bool,
141+
142+
/// Reinstall all plugin sources (implies --relock).
143+
#[structopt(long, conflicts_with = "update")]
135144
reinstall: bool,
136145
},
137146
}
@@ -199,9 +208,9 @@ pub enum Command {
199208
/// Remove a plugin from the config file.
200209
Remove { name: String },
201210
/// Install the plugins sources and generate the lock file.
202-
Lock { reinstall: bool },
211+
Lock { mode: LockMode },
203212
/// Generate and print out the script.
204-
Source { reinstall: bool, relock: bool },
213+
Source { relock: bool, mode: LockMode },
205214
}
206215

207216
/// Resolved command line options with defaults set.
@@ -215,6 +224,17 @@ pub struct Opt {
215224
pub command: Command,
216225
}
217226

227+
impl LockMode {
228+
fn from_lock_opts(update: bool, reinstall: bool) -> Self {
229+
match (update, reinstall) {
230+
(true, false) => Self::Update,
231+
(false, true) => Self::Reinstall,
232+
(false, false) => Self::Normal,
233+
(true, true) => unreachable!(),
234+
}
235+
}
236+
}
237+
218238
impl Plugin {
219239
fn from_add(add: Add) -> (String, Self) {
220240
let Add {
@@ -330,11 +350,18 @@ impl Opt {
330350
}
331351
RawCommand::Edit => Command::Edit,
332352
RawCommand::Remove { name } => Command::Remove { name },
333-
RawCommand::Lock { reinstall } => Command::Lock { reinstall },
334-
RawCommand::Source { relock, reinstall } => Command::Source {
335-
relock: relock || reinstall,
353+
RawCommand::Lock { update, reinstall } => {
354+
let mode = LockMode::from_lock_opts(update, reinstall);
355+
Command::Lock { mode }
356+
}
357+
RawCommand::Source {
358+
relock,
359+
update,
336360
reinstall,
337-
},
361+
} => {
362+
let mode = LockMode::from_lock_opts(update, reinstall);
363+
Command::Source { relock, mode }
364+
}
338365
};
339366

340367
Self {
@@ -456,7 +483,10 @@ SUBCOMMANDS:
456483
lock_file: None,
457484
clone_dir: None,
458485
download_dir: None,
459-
command: RawCommand::Lock { reinstall: false },
486+
command: RawCommand::Lock {
487+
update: false,
488+
reinstall: false
489+
},
460490
}
461491
);
462492
}
@@ -493,7 +523,10 @@ SUBCOMMANDS:
493523
lock_file: Some("/test/plugins.lock".into()),
494524
clone_dir: Some("/repos".into()),
495525
download_dir: Some("/downloads".into()),
496-
command: RawCommand::Lock { reinstall: false },
526+
command: RawCommand::Lock {
527+
update: false,
528+
reinstall: false
529+
},
497530
}
498531
);
499532
}
@@ -918,6 +951,7 @@ USAGE:
918951
{name} lock [FLAGS]
919952
920953
FLAGS:
954+
--update Update all plugin sources
921955
--reinstall Reinstall all plugin sources
922956
-h, --help Show this message and exit",
923957
name = crate_name!(),
@@ -928,6 +962,15 @@ FLAGS:
928962
assert_eq!(err.info, None);
929963
}
930964

965+
#[test]
966+
fn raw_opt_lock_with_update_and_reinstall_expect_conflict() {
967+
setup();
968+
assert_eq!(
969+
raw_opt_err(&["lock", "--update", "--reinstall"]).kind,
970+
structopt::clap::ErrorKind::ArgumentConflict
971+
);
972+
}
973+
931974
#[test]
932975
fn raw_opt_source_help() {
933976
setup();
@@ -944,6 +987,7 @@ USAGE:
944987
945988
FLAGS:
946989
--relock Regenerate the lock file
990+
--update Update all plugin sources (implies --relock)
947991
--reinstall Reinstall all plugin sources (implies --relock)
948992
-h, --help Show this message and exit",
949993
name = crate_name!(),
@@ -953,4 +997,13 @@ FLAGS:
953997
assert_eq!(err.kind, structopt::clap::ErrorKind::HelpDisplayed);
954998
assert_eq!(err.info, None);
955999
}
1000+
1001+
#[test]
1002+
fn raw_opt_source_with_update_and_reinstall_expect_conflict() {
1003+
setup();
1004+
assert_eq!(
1005+
raw_opt_err(&["source", "--update", "--reinstall"]).kind,
1006+
structopt::clap::ErrorKind::ArgumentConflict
1007+
);
1008+
}
9561009
}

src/context.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ pub struct EditContext {
4545
pub shell: Option<Shell>,
4646
}
4747

48+
/// Behaviour when locking a config file.
49+
#[derive(Debug)]
50+
pub enum LockMode {
51+
/// Apply any changed configuration.
52+
Normal,
53+
/// Apply any changed configuration and update all plugins.
54+
Update,
55+
/// Apply any changed configuration and reinstall all plugins.
56+
Reinstall,
57+
}
58+
4859
/// Contextual information to use while running the main tasks (lock and
4960
/// source).
5061
#[derive(Debug)]
@@ -53,8 +64,8 @@ pub struct LockContext {
5364
pub settings: Settings,
5465
/// The output style.
5566
pub output: Output,
56-
/// Whether to reinstall plugin sources.
57-
pub reinstall: bool,
67+
/// The relock mode.
68+
pub mode: LockMode,
5869
}
5970

6071
macro_rules! setting_access {

src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,19 @@ impl Sheldon {
258258
};
259259
Self::remove(&ctx, name)
260260
}
261-
Command::Lock { reinstall } => {
261+
Command::Lock { mode } => {
262262
let ctx = LockContext {
263263
settings,
264264
output,
265-
reinstall,
265+
mode,
266266
};
267267
Self::lock(&ctx, &mut warnings)
268268
}
269-
Command::Source { relock, reinstall } => {
269+
Command::Source { relock, mode } => {
270270
let ctx = LockContext {
271271
settings,
272272
output,
273-
reinstall,
273+
mode,
274274
};
275275
Self::source(&ctx, relock, &mut warnings)
276276
}

0 commit comments

Comments
 (0)