Skip to content

Commit

Permalink
Add subcommands to manage the xwin installation
Browse files Browse the repository at this point in the history
  • Loading branch information
nagua committed Jul 8, 2024
1 parent 58a5635 commit 3f8eff9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/bin/cargo-xwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::ffi::OsString;
use std::process::Command;

use cargo_xwin::{Build, Check, Clippy, Run, Rustc, Test};
use cargo_xwin::{Build, Check, Clippy, InitXWin, Run, Rustc, Test};
use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
Expand All @@ -12,15 +12,25 @@ use clap::{Parser, Subcommand};
styles = cargo_options::styles(),
)]
pub enum Cli {
/// Can also be used to run all the cargo commands
#[command(subcommand, name = "xwin")]
Opt(Opt),
// flatten opt here so that `cargo-xwin build` also works
#[command(flatten)]
Cargo(Opt),
/// Manage the xwin installation
#[command(subcommand, name = "manage-xwin")]
ManageXWin(ManageXWin),
#[command(external_subcommand)]
External(Vec<OsString>),
}

#[derive(Debug, Subcommand)]
#[command(version, display_order = 2)]
pub enum ManageXWin {
Init(InitXWin),
}

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Subcommand)]
#[command(version, display_order = 1)]
Expand Down Expand Up @@ -50,6 +60,9 @@ fn main() -> anyhow::Result<()> {
Opt::Check(check) => check.execute()?,
Opt::Clippy(clippy) => clippy.execute()?,
},
Cli::ManageXWin(opt) => match opt {
ManageXWin::Init(init) => init.execute()?,
},
Cli::External(args) => {
let mut child = Command::new(env::var_os("CARGO").unwrap_or("cargo".into()))
.args(args)
Expand Down
37 changes: 37 additions & 0 deletions src/init_xwin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::{path::PathBuf, process::Command};

use anyhow::Result;
use cargo_options::heading;
use clap::Parser;

use crate::common::XWinOptions;

#[derive(Clone, Debug, Default, Parser)]
#[command(
display_order = 1,
about = "Run init command",
after_help = "",
)]
pub struct InitXWin {
#[command(flatten)]
common: cargo_options::CommonOptions,

/// Path to Cargo.toml
#[arg(long, value_name = "PATH", help_heading = heading::MANIFEST_OPTIONS)]
pub manifest_path: Option<PathBuf>,

#[command(flatten)]
xwin: XWinOptions,
}

impl InitXWin {
pub fn execute(&self) -> Result<()> {
let mut build = Command::new("");
self.xwin.apply_command_env(
self.manifest_path.as_deref(),
&self.common,
&mut build,
)?;
Ok(())
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod common;
mod init_xwin;
mod macros;
mod run;
mod test;

pub use common::XWinOptions;
pub use init_xwin::InitXWin;
pub use macros::{build::Build, check::Check, clippy::Clippy, rustc::Rustc};
pub use run::Run;
pub use test::Test;

0 comments on commit 3f8eff9

Please sign in to comment.