From 381f3ffcfc709d91bbaab7e216adebe6deb02f7f Mon Sep 17 00:00:00 2001 From: fluo10 Date: Tue, 13 May 2025 19:43:52 +0900 Subject: [PATCH] Merge cli to client --- Cargo.lock | 13 ---- Cargo.toml | 5 +- progress-pile-cli/Cargo.toml | 15 ---- progress-pile-cli/src/config.rs | 0 progress-pile-cli/src/init.rs | 73 ------------------- progress-pile-cli/src/label.rs | 0 progress-pile-cli/src/main.rs | 42 ----------- progress-pile-cli/src/record.rs | 59 --------------- progress-pile-client/src/cli/category.rs | 27 +++++++ progress-pile-client/src/cli/config.rs | 26 +++++++ progress-pile-client/src/cli/default.rs | 16 ++++ progress-pile-client/src/cli/login.rs | 18 +++++ progress-pile-client/src/cli/mod.rs | 50 +++++++++++++ .../src/cli}/user.rs | 2 - progress-pile-client/src/lib.rs | 6 +- progress-pile-client/src/main.rs | 8 ++ 16 files changed, 150 insertions(+), 210 deletions(-) delete mode 100644 progress-pile-cli/Cargo.toml delete mode 100644 progress-pile-cli/src/config.rs delete mode 100644 progress-pile-cli/src/init.rs delete mode 100644 progress-pile-cli/src/label.rs delete mode 100644 progress-pile-cli/src/main.rs delete mode 100644 progress-pile-cli/src/record.rs create mode 100644 progress-pile-client/src/cli/category.rs create mode 100644 progress-pile-client/src/cli/config.rs create mode 100644 progress-pile-client/src/cli/default.rs create mode 100644 progress-pile-client/src/cli/login.rs create mode 100644 progress-pile-client/src/cli/mod.rs rename {progress-pile-cli/src => progress-pile-client/src/cli}/user.rs (89%) create mode 100644 progress-pile-client/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 7ca3599..af02a5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2240,19 +2240,6 @@ dependencies = [ "yansi", ] -[[package]] -name = "progress-pile-cli" -version = "0.1.0" -dependencies = [ - "chrono", - "chrono-tz", - "clap", - "progress-pile-client", - "thiserror 2.0.12", - "tokio", - "toml", -] - [[package]] name = "progress-pile-client" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 19fd889..c1455ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,9 +8,8 @@ chrono-tz = {version = "0.10.3", features = ["serde"]} clap = {version = "4.5", features = ["derive"]} dirs = "6.0.0" dotenv = "0.15.0" -progress-pile-cli.path = "progress-pile-cli" -progress-pile-client.path = "progress-pile-client" -progress-pile-core = { path = "progress-pile-core", default-features = false} +progress-pile-client = { path = "progress-pile-client", default-features = false } +progress-pile-core = { path = "progress-pile-core", default-features = false } progress-pile-migration = { path = "progress-pile-migration", default-features = false } progress-pile-server.path = "progress-pile-server" serde = { version = "1.0", features = ["derive"] } diff --git a/progress-pile-cli/Cargo.toml b/progress-pile-cli/Cargo.toml deleted file mode 100644 index 0c4910b..0000000 --- a/progress-pile-cli/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "progress-pile-cli" -version.workspace = true -license.workspace = true -edition.workspace = true -repository.workspace = true - -[dependencies] -progress-pile-client = {workspace = true} -chrono = {workspace = true} -chrono-tz.workspace = true -clap = {workspace = true, features = ["derive"]} -thiserror.workspace = true -tokio.workspace = true -toml.workspace = true \ No newline at end of file diff --git a/progress-pile-cli/src/config.rs b/progress-pile-cli/src/config.rs deleted file mode 100644 index e69de29..0000000 diff --git a/progress-pile-cli/src/init.rs b/progress-pile-cli/src/init.rs deleted file mode 100644 index c21fc7e..0000000 --- a/progress-pile-cli/src/init.rs +++ /dev/null @@ -1,73 +0,0 @@ -use clap::{Args, Subcommand}; -use chrono_tz::Tz; -use crate::error::Error; -use progress_pile_client::auth::try_login; -use progress_pile_client::config::{ - ClientConfig, ClientRemoteStorageConfig, ClientStorageConfig, Config, GlobalConfig, PartialGlobalConfig -}; - -#[derive(Args, Clone, Debug)] -pub struct InitArgs { - #[command(subcommand)] - pub command: InitCommand, -} - -impl InitArgs { - pub async fn run(self) -> Result<(), Error> { - match self.command { - InitCommand::Local(x) => x.run().await, - InitCommand::Remote(x) => x.run().await, - } - } -} -#[derive(Clone, Debug, Subcommand)] - -enum InitCommand { - Local(InitLocalArgs), - Remote(InitRemoteArgs), -} - -#[derive(Args, Clone, Debug)] -pub struct InitLocalArgs { - #[arg(short, long)] - pub time_zone: Option, - #[arg(short, long)] - pub force: bool -} - -impl InitLocalArgs { - pub async fn run(self) -> Result<(), Error> { - unimplemented!() - } -} - -#[derive(Args, Clone, Debug)] -pub struct InitRemoteArgs { - pub endpoint: String, - #[arg(short, long)] - pub user_name: String, - #[arg(short, long)] - pub password: String, - #[arg(short, long)] - pub time_zone: Option, - #[arg(short, long)] - pub force: bool, -} - -impl InitRemoteArgs { - pub async fn run(self) -> Result<(), Error> { - let token: String = try_login(&self.user_name, &self.password, &self.endpoint)?; - let config: Config = Config{ - global: GlobalConfig { - time_zone: self.time_zone.clone() - }, - client: ClientConfig { - storage: ClientStorageConfig::Remote(ClientRemoteStorageConfig { - endpoint: self.endpoint, - access_key: token, - }), - } - }; - config.write_to_default_toml().await - } -} diff --git a/progress-pile-cli/src/label.rs b/progress-pile-cli/src/label.rs deleted file mode 100644 index e69de29..0000000 diff --git a/progress-pile-cli/src/main.rs b/progress-pile-cli/src/main.rs deleted file mode 100644 index 210ccb5..0000000 --- a/progress-pile-cli/src/main.rs +++ /dev/null @@ -1,42 +0,0 @@ -//mod label; -mod init; -mod record; -mod user; - -pub use progress_pile_client::error; - - -//use label::LabelArgs; -use record::{RecordArgs,RecordAddArgs}; - -use error::Error; -use init::InitArgs; -use clap::{Args, CommandFactory, Parser, Subcommand}; - -use std::ffi::OsString; - -#[derive(Parser)] -#[command(version, about, long_about = None)] -#[command(propagate_version=true)] -struct Cli { - #[command(subcommand)] - command: Command, -} - -#[derive(Clone, Debug, Subcommand)] -enum Command { - Init(InitArgs), - Record(RecordArgs), -} - -#[tokio::main] -async fn main() -> Result<(), Error> { - let cli = Cli::parse(); - match cli.command { - //Some(Commands::Add(x)) => x.run(), - Command::Init(x) => x.run().await, - //Some(Commands::Label(x)) => x.run(), - Command::Record(x) => x.run(), - - } -} diff --git a/progress-pile-cli/src/record.rs b/progress-pile-cli/src/record.rs deleted file mode 100644 index 30b59eb..0000000 --- a/progress-pile-cli/src/record.rs +++ /dev/null @@ -1,59 +0,0 @@ -use chrono::prelude::*; -use clap::{Args, Subcommand}; -use crate::error::Error; -use std::str::FromStr; - -#[derive(Args, Clone, Debug)] -pub struct AchievementArgValues { - pub label: String, - pub value: i8, -} - -impl FromStr for AchievementArgValues { - type Err = Error; - fn from_str(s: &str) -> Result { - let strvec: Vec<&str> = s.split(':').collect(); - Ok(AchievementArgValues{ - label: strvec.get(0).unwrap().to_string(), - value: strvec.get(1).unwrap().parse()? - }) - } -} - - -#[derive(Args, Clone, Debug)] -pub struct RecordAddArgs { - #[arg(short, long)] - pub comment: Option, - #[arg(short, long)] - pub time: Option>, - //pub achievements: Vec, -} - -impl RecordAddArgs { - pub fn run(self) -> Result<(), Error> { - unimplemented!(); - } -} - -#[derive(Clone, Debug, Subcommand)] -pub enum RecordCommand { - Add(RecordAddArgs), -} - -#[derive(Args, Clone, Debug)] -pub struct RecordArgs { - #[command(subcommand)] - command: RecordCommand, -} - -impl RecordArgs { - pub fn run(self) -> Result<(), Error> { - match self.command { - RecordCommand::Add(x) => x.run(), - } - } -} - - - diff --git a/progress-pile-client/src/cli/category.rs b/progress-pile-client/src/cli/category.rs new file mode 100644 index 0000000..e765142 --- /dev/null +++ b/progress-pile-client/src/cli/category.rs @@ -0,0 +1,27 @@ +use clap::{Args, Subcommand}; + + +#[derive(Args, Clone, Debug)] +pub struct CategoryArgs { + #[command(subcommand)] + pub command: CategoryCommand, +} + +impl CategoryArgs { + pub async fn run(self){ + self.command.run().await + } +} +#[derive(Clone, Debug, Subcommand)] + +enum CategoryCommand { + List, + Add, + Modify, +} + +impl CategoryCommand { + async fn run(self) { + todo!() + } +} \ No newline at end of file diff --git a/progress-pile-client/src/cli/config.rs b/progress-pile-client/src/cli/config.rs new file mode 100644 index 0000000..b29abf6 --- /dev/null +++ b/progress-pile-client/src/cli/config.rs @@ -0,0 +1,26 @@ +use clap::{Args, Subcommand}; + + +#[derive(Args, Clone, Debug)] +pub struct ConfigArgs { + #[command(subcommand)] + pub command: ConfigCommand, +} + +impl ConfigArgs { + pub async fn run(self){ + self.command.run().await + } +} +#[derive(Clone, Debug, Subcommand)] + +enum ConfigCommand { + Show, + Modify, +} + +impl ConfigCommand { + async fn run(self) { + todo!() + } +} \ No newline at end of file diff --git a/progress-pile-client/src/cli/default.rs b/progress-pile-client/src/cli/default.rs new file mode 100644 index 0000000..c68b67b --- /dev/null +++ b/progress-pile-client/src/cli/default.rs @@ -0,0 +1,16 @@ +use clap::{Args, Subcommand}; + + +#[derive(Args, Clone, Debug)] +pub struct DefaultArgs { + #[arg(short, long)] + pub note: String, + pub category: String, + pub quantity: i32, +} + +impl DefaultArgs { + pub async fn run (self) { + todo!() + } +} \ No newline at end of file diff --git a/progress-pile-client/src/cli/login.rs b/progress-pile-client/src/cli/login.rs new file mode 100644 index 0000000..43e92a5 --- /dev/null +++ b/progress-pile-client/src/cli/login.rs @@ -0,0 +1,18 @@ +use clap::{Args, Subcommand}; +use chrono_tz::Tz; +use crate::error::Error; + +#[derive(Args, Clone, Debug)] +pub struct LoginArgs { + pub endpoint: String, + #[arg(short, long)] + pub user_name: String, + #[arg(short, long)] + pub password: String, +} + +impl LoginArgs { + pub async fn run(self){ + todo!() + } +} diff --git a/progress-pile-client/src/cli/mod.rs b/progress-pile-client/src/cli/mod.rs new file mode 100644 index 0000000..5146c29 --- /dev/null +++ b/progress-pile-client/src/cli/mod.rs @@ -0,0 +1,50 @@ +//mod label; +mod category; +mod config; +mod default; +mod login; +mod user; + +use category::CategoryArgs; +use config::ConfigArgs; +use default::DefaultArgs; +use login::LoginArgs; +use user::UserArgs; + +use clap::{Args, CommandFactory, Parser, Subcommand}; + +use std::ffi::OsString; + +#[derive(Parser)] +#[command(version, about, long_about = None)] +#[command(propagate_version=true)] +pub struct Cli { + #[command(subcommand)] + command: Option, + #[command(flatten)] + args: Option +} + +impl Cli { + pub async fn run(self) { + if let Some(x) = self.command { + x.run().await + } else if let Some(x) = self.args { + x.run().await + } + } +} + +#[derive(Clone, Debug, Subcommand)] +enum Command { + Category(CategoryArgs), + Config(ConfigArgs), + Login(LoginArgs), + User(UserArgs), +} + +impl Command { + pub async fn run(self) { + todo!() + } +} diff --git a/progress-pile-cli/src/user.rs b/progress-pile-client/src/cli/user.rs similarity index 89% rename from progress-pile-cli/src/user.rs rename to progress-pile-client/src/cli/user.rs index 55e68cd..b1fa393 100644 --- a/progress-pile-cli/src/user.rs +++ b/progress-pile-client/src/cli/user.rs @@ -1,6 +1,5 @@ use clap::{Args, Subcommand}; use crate::error::Error; -use progress_pile_client::config::Config; #[derive(Args, Clone, Debug)] @@ -11,7 +10,6 @@ pub struct UserArgs { impl UserArgs { pub async fn run(self) -> Result<(), Error> { - Config::read_from_default_toml().await?.set_global(); match self.command { UserCommand::Add(x) => x.add().await, UserCommand::List => todo!(), diff --git a/progress-pile-client/src/lib.rs b/progress-pile-client/src/lib.rs index 339cf71..8e22968 100644 --- a/progress-pile-client/src/lib.rs +++ b/progress-pile-client/src/lib.rs @@ -1,12 +1,12 @@ pub mod auth; +#[cfg(feature="desktop")] +pub mod cli; pub mod config; #[cfg(feature="desktop")] pub mod entity; pub mod global; -pub use progress_pile_core::{ - error, -}; +pub use progress_pile_core::error; diff --git a/progress-pile-client/src/main.rs b/progress-pile-client/src/main.rs new file mode 100644 index 0000000..8ef2d7a --- /dev/null +++ b/progress-pile-client/src/main.rs @@ -0,0 +1,8 @@ +use clap::Parser; +use progress_pile_client::cli::Cli; + +#[tokio::main] +async fn main() { + let cli = Cli::parse(); + cli.run().await +}