Move Cli and Commands definitions into cli module

This commit is contained in:
Aadi Desai 2023-04-22 18:16:07 +01:00
parent 2d29a930af
commit 168f90b9a8
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 39 additions and 35 deletions

35
src/cli.rs Normal file
View file

@ -0,0 +1,35 @@
use clap::{Parser, Subcommand};
#[derive(Parser)]
pub struct Cli {
/// Set a custom username
#[clap(short, long)]
pub username: Option<String>,
#[clap(subcommand)]
pub command: Option<Commands>,
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
}
#[derive(Subcommand)]
pub enum Commands {
Auth {
api_key: String,
},
Weblog {
#[arg(short, long)]
yay: u8,
#[arg(short, long)]
nay: Option<u8>,
},
Status {
#[arg(long)]
message: String,
/// Does this explain it?
req: String,
},
}

View file

@ -1,49 +1,18 @@
use anyhow::Context; use anyhow::Context;
use clap::{Parser, Subcommand}; use clap::Parser;
use directories::ProjectDirs; use directories::ProjectDirs;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fs::read_to_string; use std::fs::read_to_string;
mod cli;
use cli::{Cli, Commands};
#[derive(Default, Deserialize, Serialize)] #[derive(Default, Deserialize, Serialize)]
struct Config { struct Config {
api_key: Option<String>, api_key: Option<String>,
username: Option<String>, username: Option<String>,
} }
#[derive(Parser)]
struct Cli {
/// Set a custom username
#[clap(short, long)]
username: Option<String>,
#[clap(subcommand)]
command: Option<Commands>,
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
}
#[derive(Subcommand)]
enum Commands {
Auth {
api_key: String,
},
Weblog {
#[arg(short, long)]
yay: u8,
#[arg(short, long)]
nay: Option<u8>,
},
Status {
#[arg(long)]
message: String,
/// Does this explain it?
req: String,
},
}
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();