GitHub

@@ -11,7 +11,7 @@ use url::Url;

11111212

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

}

206215207216

/// Resolved command line options with defaults set.

@@ -215,6 +224,17 @@ pub struct Opt {

215224

pub command: Command,

216225

}

217226227+

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

};

339366340367

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]

919952920953

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

}

930964965+

#[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:

944987945988

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

}

Read the original on github.com ↗