Skip to content

Commit

Permalink
refactor(app): make delete flag global to reduce copypasta
Browse files Browse the repository at this point in the history
  • Loading branch information
norskeld committed Mar 11, 2024
1 parent 6490556 commit a94e985
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub enum AppError {
pub struct Cli {
#[command(subcommand)]
pub command: BaseCommand,

/// Delete arx config after scaffolding.
#[arg(global = true, short, long)]
delete: Option<bool>,
}

#[derive(Debug, Subcommand)]
Expand All @@ -44,10 +48,6 @@ pub enum BaseCommand {
/// Scaffold from a specified ref (branch, tag, or commit).
#[arg(name = "REF", short = 'r', long = "ref")]
meta: Option<String>,

/// Delete arx config after scaffolding.
#[arg(short, long)]
delete: Option<bool>,
},
/// Scaffold from a local repository.
#[command(visible_alias = "l")]
Expand All @@ -61,10 +61,6 @@ pub enum BaseCommand {
/// Scaffold from a specified ref (branch, tag, or commit).
#[arg(name = "REF", short = 'r', long = "ref")]
meta: Option<String>,

/// Delete arx config after scaffolding.
#[arg(short, long)]
delete: Option<bool>,
},
}

Expand All @@ -90,16 +86,12 @@ impl App {
)
}))?;

let overrides = ConfigOptionsOverrides { delete: self.cli.delete };

// Load the config.
let config = match self.cli.command {
| BaseCommand::Remote { src, path, meta, delete } => {
let options = ConfigOptionsOverrides { delete };
Self::remote(src, path, meta, options).await?
},
| BaseCommand::Local { src, path, meta, delete } => {
let options = ConfigOptionsOverrides { delete };
Self::local(src, path, meta, options).await?
},
| BaseCommand::Remote { src, path, meta } => Self::remote(src, path, meta, overrides).await?,
| BaseCommand::Local { src, path, meta } => Self::local(src, path, meta, overrides).await?,
};

// Create executor and kick off execution.
Expand Down

0 comments on commit a94e985

Please sign in to comment.