Merge cli to client
This commit is contained in:
parent
5700d19a85
commit
381f3ffcfc
16 changed files with 150 additions and 210 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
@ -2240,19 +2240,6 @@ dependencies = [
|
||||||
"yansi",
|
"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]]
|
[[package]]
|
||||||
name = "progress-pile-client"
|
name = "progress-pile-client"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
|
@ -8,8 +8,7 @@ chrono-tz = {version = "0.10.3", features = ["serde"]}
|
||||||
clap = {version = "4.5", features = ["derive"]}
|
clap = {version = "4.5", features = ["derive"]}
|
||||||
dirs = "6.0.0"
|
dirs = "6.0.0"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
progress-pile-cli.path = "progress-pile-cli"
|
progress-pile-client = { path = "progress-pile-client", default-features = false }
|
||||||
progress-pile-client.path = "progress-pile-client"
|
|
||||||
progress-pile-core = { path = "progress-pile-core", 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-migration = { path = "progress-pile-migration", default-features = false }
|
||||||
progress-pile-server.path = "progress-pile-server"
|
progress-pile-server.path = "progress-pile-server"
|
||||||
|
|
|
@ -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
|
|
|
@ -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<Tz>,
|
|
||||||
#[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<Tz>,
|
|
||||||
#[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
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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(),
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<Self, Error> {
|
|
||||||
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<String>,
|
|
||||||
#[arg(short, long)]
|
|
||||||
pub time: Option<DateTime<Utc>>,
|
|
||||||
//pub achievements: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
27
progress-pile-client/src/cli/category.rs
Normal file
27
progress-pile-client/src/cli/category.rs
Normal file
|
@ -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!()
|
||||||
|
}
|
||||||
|
}
|
26
progress-pile-client/src/cli/config.rs
Normal file
26
progress-pile-client/src/cli/config.rs
Normal file
|
@ -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!()
|
||||||
|
}
|
||||||
|
}
|
16
progress-pile-client/src/cli/default.rs
Normal file
16
progress-pile-client/src/cli/default.rs
Normal file
|
@ -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!()
|
||||||
|
}
|
||||||
|
}
|
18
progress-pile-client/src/cli/login.rs
Normal file
18
progress-pile-client/src/cli/login.rs
Normal file
|
@ -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!()
|
||||||
|
}
|
||||||
|
}
|
50
progress-pile-client/src/cli/mod.rs
Normal file
50
progress-pile-client/src/cli/mod.rs
Normal file
|
@ -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>,
|
||||||
|
#[command(flatten)]
|
||||||
|
args: Option<DefaultArgs>
|
||||||
|
}
|
||||||
|
|
||||||
|
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!()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
use clap::{Args, Subcommand};
|
use clap::{Args, Subcommand};
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use progress_pile_client::config::Config;
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Args, Clone, Debug)]
|
#[derive(Args, Clone, Debug)]
|
||||||
|
@ -11,7 +10,6 @@ pub struct UserArgs {
|
||||||
|
|
||||||
impl UserArgs {
|
impl UserArgs {
|
||||||
pub async fn run(self) -> Result<(), Error> {
|
pub async fn run(self) -> Result<(), Error> {
|
||||||
Config::read_from_default_toml().await?.set_global();
|
|
||||||
match self.command {
|
match self.command {
|
||||||
UserCommand::Add(x) => x.add().await,
|
UserCommand::Add(x) => x.add().await,
|
||||||
UserCommand::List => todo!(),
|
UserCommand::List => todo!(),
|
|
@ -1,12 +1,12 @@
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
|
#[cfg(feature="desktop")]
|
||||||
|
pub mod cli;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
#[cfg(feature="desktop")]
|
#[cfg(feature="desktop")]
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod global;
|
pub mod global;
|
||||||
|
|
||||||
pub use progress_pile_core::{
|
pub use progress_pile_core::error;
|
||||||
error,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
8
progress-pile-client/src/main.rs
Normal file
8
progress-pile-client/src/main.rs
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue