Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subcommands to manage the xwin installation #117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading