Skip to content

Commit

Permalink
useing clap default macros for mutual exclsion [Improvement]: Head an…
Browse files Browse the repository at this point in the history
…d tail args for the log command shuttle-hq#1600
  • Loading branch information
biplab5464 committed Feb 12, 2024
1 parent 5cf9028 commit a6cfe7d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ pub enum Command {
/// Don't display timestamps and log origin tags
raw: bool,
/// Views First N line of the logs
#[arg(long)]
#[arg(long, group = "output_mode")]
head: Option<u32>,
/// Views Last N line of the logs
#[arg(long)]
#[arg(long, group = "output_mode")]
tail: Option<u32>,
/// Views all line of the logs
#[arg(long)]
#[arg(long, group = "output_mode")]
all: bool,
},
/// List or manage projects on Shuttle
Expand Down
25 changes: 11 additions & 14 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ impl Shuttle {
latest,
follow,
raw,
head ,
head,
tail,
all
all,
} => self.logs(id, latest, follow, raw, head, tail, all).await,
Command::Deployment(DeploymentCommand::List { page, limit, raw }) => {
self.deployments_list(page, limit, raw).await
Expand Down Expand Up @@ -741,19 +741,16 @@ impl Shuttle {
latest: bool,
follow: bool,
raw: bool,
head : Option<u32>,
tail : Option<u32>,
all : bool
head: Option<u32>,
tail: Option<u32>,
all: bool,
) -> Result<CommandOutcome> {

let mut count = 0;
let mut mode =("tail",1000);
if let Some(num) = head { count += 1; mode = ("head",num) }
if let Some(num) = tail { count += 1; mode = ("tail",num) }
if all { count += 1; mode = ("all",0) }

if count > 1 {
bail!("Error: Only one of 'head', 'tail', or 'all' can be used at a time.")
let mode: (&str, u32);
match (head, tail, all) {
(Some(num), _, _) => mode = ("head", num),
(_, Some(num), _) => mode = ("tail", num),
(_, _, all) if all => mode = ("all", 0),
_ => mode = ("tail", 1000),
}

let client = self.client.as_ref().unwrap();
Expand Down

0 comments on commit a6cfe7d

Please sign in to comment.