Skip to content

Commit

Permalink
Merge pull request #2 from daniloegea/clap_fixes
Browse files Browse the repository at this point in the history
Clap fixes for the "run" command
  • Loading branch information
michael-yuji authored Sep 23, 2023
2 parents fa70792 + f6e4879 commit 4e4676d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
20 changes: 14 additions & 6 deletions xc-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use freebsd::procdesc::{pd_fork, pdwait, PdForkResult};
use ipc::packet::codec::{Fd, Maybe};
use oci_util::digest::OciDigest;
use oci_util::image_reference::ImageReference;
use run::PublishArgs;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::os::fd::AsRawFd;
Expand Down Expand Up @@ -110,7 +111,12 @@ enum Action {
tag: String,
container_name: String,
},
Create(CreateArgs),
Create {
#[command(flatten)]
create: CreateArgs,
#[command(flatten)]
publish: PublishArgs,
},
#[command(subcommand)]
Image(ImageAction),
Info,
Expand Down Expand Up @@ -173,6 +179,8 @@ enum Action {
#[command(flatten)]
dns: DnsArgs,
#[command(flatten)]
publish: PublishArgs,
#[command(flatten)]
args: RunArg,
},
RunMain {
Expand Down Expand Up @@ -546,11 +554,11 @@ fn main() -> Result<(), ActionError> {
Action::Rdr(rdr) => {
_ = use_rdr_action(&mut conn, rdr);
}
Action::Create(args) => {
let publish = args.publish.clone();
Action::Create {create, publish} => {
let publish = publish.publish.clone();

let res = {
let reqt = args.create_request()?;
let reqt = create.create_request()?;
do_instantiate(&mut conn, reqt)?
};

Expand All @@ -567,7 +575,7 @@ fn main() -> Result<(), ActionError> {
eprintln!("{res:#?}");
}
}
Action::Run { create, dns, args } => {
Action::Run { create, dns, publish, args } => {
if args.detach && args.link {
panic!("detach and link flags are mutually exclusive");
}
Expand All @@ -576,7 +584,7 @@ fn main() -> Result<(), ActionError> {
panic!("--dns-nop and --empty-dns are mutually exclusive");
}

let publish = args.publish.clone();
let publish = publish.publish.clone();

let dns = dns.make();

Expand Down
14 changes: 7 additions & 7 deletions xc-bin/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,24 @@ impl DnsArgs {
}
}

#[derive(Parser, Debug)]
pub(crate) struct PublishArgs {
#[arg(long = "publish", short = 'p')]
pub(crate) publish: Vec<PublishSpec>,
}

#[derive(Parser, Debug)]
pub(crate) struct RunArg {
#[arg(long = "link", action)]
pub(crate) link: bool,

#[arg(long = "publish", short = 'p', /* multiple_occurrences */)]
pub(crate) publish: Vec<PublishSpec>,

#[arg(long = "detach", short = 'd', action)]
pub(crate) detach: bool,

#[arg(long = "user", short = 'u', action)]
pub(crate) user: Option<String>,

#[arg(long = "group", short = 'u', action)]
#[arg(long = "group", short = 'g', action)]
pub(crate) group: Option<String>,

pub(crate) entry_point: Option<String>,
Expand Down Expand Up @@ -129,9 +132,6 @@ pub(crate) struct CreateArgs {
#[arg(long = "extra-layer", /* multiple_occurrences */)]
pub(crate) extra_layers: Vec<PathBuf>,

#[arg(long = "publish", short = 'p', /* multiple_occurrences */)]
pub(crate) publish: Vec<PublishSpec>,

pub(crate) image_reference: ImageReference,

#[arg(long = "net-group")]
Expand Down

0 comments on commit 4e4676d

Please sign in to comment.