Add 'packages upgrade' command.

This commit is contained in:
KtorZ 2023-01-14 23:24:26 +01:00
parent 6286132a3e
commit 219e81cb75
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 44 additions and 8 deletions

View File

@ -17,10 +17,13 @@ pub struct Args {
/// ///
/// Note that by default, this assumes the package is located /// Note that by default, this assumes the package is located
/// on Github. /// on Github.
package: String, pub package: String,
/// The package version, as a git commit hash, a tag or a branch name. /// The package version, as a git commit hash, a tag or a branch name.
#[clap(long)] #[clap(long)]
version: String, pub version: String,
#[clap(hide = true)]
pub overwrite: bool,
} }
pub fn exec(args: Args) -> miette::Result<()> { pub fn exec(args: Args) -> miette::Result<()> {
@ -42,18 +45,22 @@ pub fn exec(args: Args) -> miette::Result<()> {
println!( println!(
"{} {}", "{} {}",
pretty::pad_left("Adding".to_string(), 13, " ") pretty::pad_left("Package".to_string(), 13, " ")
.bold() .bold()
.purple(), .purple(),
dependency.name.bright_blue(), dependency.name.bright_blue(),
); );
match config.insert(&dependency, false) { match config.insert(&dependency, args.overwrite) {
Some(config) => { Some(config) => {
config.save(&root).into_diagnostic()?; config.save(&root).into_diagnostic()?;
println!( println!(
"{} version = {}", "{} version → {}",
pretty::pad_left("Added".to_string(), 13, " ") pretty::pad_left(
if args.overwrite { "Changed" } else { "Added" }.to_string(),
13,
" "
)
.bold() .bold()
.purple(), .purple(),
dependency.version.yellow() dependency.version.yellow()

View File

@ -1,5 +1,6 @@
pub mod add; pub mod add;
pub mod clear_cache; pub mod clear_cache;
pub mod upgrade;
use clap::Subcommand; use clap::Subcommand;
@ -10,6 +11,9 @@ pub enum Cmd {
/// Add a new package dependency /// Add a new package dependency
Add(add::Args), Add(add::Args),
/// Change the version of an installed dependency
Upgrade(upgrade::Args),
/// Clear the system-wide dependencies cache /// Clear the system-wide dependencies cache
ClearCache, ClearCache,
} }
@ -18,5 +22,6 @@ pub fn exec(cmd: Cmd) -> miette::Result<()> {
match cmd { match cmd {
Cmd::Add(args) => add::exec(args), Cmd::Add(args) => add::exec(args),
Cmd::ClearCache => clear_cache::exec(), Cmd::ClearCache => clear_cache::exec(),
Cmd::Upgrade(args) => upgrade::exec(args),
} }
} }

View File

@ -0,0 +1,24 @@
use super::add;
#[derive(clap::Args)]
/// Change the version of an installed dependency
pub struct Args {
/// Package name, in the form of {owner}/{repository}.
///
/// For example → 'add aiken-lang/stdlib'
///
/// Note that by default, this assumes the package is located
/// on Github.
package: String,
/// The package version, as a git commit hash, a tag or a branch name.
#[clap(long)]
version: String,
}
pub fn exec(args: Args) -> miette::Result<()> {
add::exec(add::Args {
package: args.package,
version: args.version,
overwrite: true,
})
}