Skip to content

Commit

Permalink
migrate from structops to clap
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiyaa committed Mar 15, 2024
1 parent 86a10b6 commit 2123074
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 137 deletions.
152 changes: 48 additions & 104 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ path = "src/bin/client/main.rs"
[dependencies]
alphanumeric-sort = "^1"
chrono = "^0"
clap = { version = "^4", features = ["derive"] }
crossbeam = "^0"
dirs-next = "^2"
env_logger = "^0"
Expand All @@ -42,7 +43,6 @@ shellexpand = "^2"
signal-hook = "^0"
skim = "^0"
strfmt = "^0"
structopt = "^0"
termion = "^1"
toml = "^0"
unicode-width = "^0"
Expand Down
1 change: 0 additions & 1 deletion src/bin/client/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ pub mod app_event;
pub mod process_event;

pub use self::app_event::*;

31 changes: 16 additions & 15 deletions src/bin/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use std::process;
use std::thread;
use std::time;

use dizi::error::DiziResult;
use clap::Parser;
use lazy_static::lazy_static;
use structopt::StructOpt;

use dizi::error::DiziResult;

use crate::config::{
AppConfig, AppKeyMapping, AppLayout, AppTheme, JsonConfigFile, TomlConfigFile,
Expand Down Expand Up @@ -71,31 +72,31 @@ lazy_static! {
static ref LAYOUT_T: AppLayout = AppLayout::get_config(LAYOUT_FILE);
}

#[derive(Clone, Debug, StructOpt)]
pub struct Args {
#[derive(Clone, Debug, Parser)]
pub struct CommandArgs {
// version
#[structopt(short = "v", long = "version")]
#[arg(short = 'v', long = "version")]
version: bool,

// query
#[structopt(short = "Q", long = "query")]
#[arg(short = 'Q', long = "query")]
query: Option<String>,
// query
#[structopt(long = "query-all")]
#[arg(long = "query-all")]
query_all: bool,

// controls
#[structopt(long = "exit")]
#[arg(long = "exit")]
exit: bool,
#[structopt(long = "next")]
#[arg(long = "next")]
next: bool,
#[structopt(long = "previous")]
#[arg(long = "previous")]
previous: bool,
#[structopt(long = "pause")]
#[arg(long = "pause")]
pause: bool,
#[structopt(long = "resume")]
#[arg(long = "resume")]
resume: bool,
#[structopt(long = "toggle-pause")]
#[arg(long = "toggle-pause")]
toggle_play: bool,
}

Expand All @@ -113,7 +114,7 @@ fn create_context(config: AppConfig, cwd: &Path, stream: UnixStream) -> AppConte
AppContext::new(config, cwd.to_path_buf(), stream)
}

fn run_app(args: Args) -> DiziResult {
fn run_app(args: CommandArgs) -> DiziResult {
// print version
if args.version {
let version = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -195,7 +196,7 @@ fn run_app(args: Args) -> DiziResult {
}

fn main() {
let args = Args::from_args();
let args = CommandArgs::parse();

match run_app(args) {
Ok(_) => {}
Expand Down
4 changes: 2 additions & 2 deletions src/bin/client/run/run_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use dizi::request::client::ClientRequest;

use crate::context::AppContext;
use crate::util::request::send_client_request;
use crate::Args;
use crate::CommandArgs;

pub fn run_control(context: &mut AppContext, args: &Args) -> DiziResult {
pub fn run_control(context: &mut AppContext, args: &CommandArgs) -> DiziResult {
let request = if args.exit {
Some(ClientRequest::ServerQuit)
} else if args.next {
Expand Down
13 changes: 7 additions & 6 deletions src/bin/server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ mod util;

use std::path::PathBuf;

use clap::Parser;

use lazy_static::lazy_static;
use log::{debug, log_enabled, Level};
use structopt::StructOpt;

use dizi::error::DiziResult;

Expand Down Expand Up @@ -58,13 +59,13 @@ lazy_static! {
static ref HOME_DIR: Option<PathBuf> = dirs_next::home_dir();
}

#[derive(Clone, Debug, StructOpt)]
pub struct Args {
#[structopt(short = "v", long = "version")]
#[derive(Clone, Debug, Parser)]
pub struct CommandArgs {
#[arg(short = 'v', long = "version")]
version: bool,
}

fn run_server(args: Args) -> DiziResult {
fn run_server(args: CommandArgs) -> DiziResult {
if args.version {
let version = env!("CARGO_PKG_VERSION");
println!("{}", version);
Expand All @@ -82,7 +83,7 @@ fn run_server(args: Args) -> DiziResult {
fn main() {
env_logger::init();

let args = Args::from_args();
let args = CommandArgs::parse();
let res = run_server(args);

match res {
Expand Down
3 changes: 0 additions & 3 deletions src/bin/server/playlist/playlist_directory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
mod impl_ordered_playlist;
mod impl_shuffle_playlist;




use std::fs;
use std::io;
use std::path::Path;
Expand Down
Loading

0 comments on commit 2123074

Please sign in to comment.