From 9b0d3bac69e758420f7beb35919bc8cb2042c21f Mon Sep 17 00:00:00 2001 From: vsevolod Date: Fri, 15 Nov 2024 17:35:00 +0100 Subject: [PATCH 1/8] Test task Google Sheets CLI --- module/move/gspread/Cargo.toml | 25 +-- module/move/gspread/design/commands.md | 27 ++++ .../gspread/src/commands/gspread_cells.rs | 142 +++++++++--------- .../move/gspread/src/debug/table_wrapper.rs | 58 +++++++ module/move/gspread/src/lib.rs | 38 +---- module/move/gspread/src/secret.rs | 20 +-- 6 files changed, 171 insertions(+), 139 deletions(-) create mode 100644 module/move/gspread/design/commands.md create mode 100644 module/move/gspread/src/debug/table_wrapper.rs diff --git a/module/move/gspread/Cargo.toml b/module/move/gspread/Cargo.toml index 7d75b04122..e31800d872 100644 --- a/module/move/gspread/Cargo.toml +++ b/module/move/gspread/Cargo.toml @@ -17,31 +17,16 @@ default-run = "main" name = "main" path = "src/bin/main.rs" -[features] -default = [ "enabled" ] -full = [ "enabled" ] -enabled = [ - "former/enabled", - "format_tools/enabled", - "reflect_tools/enabled", -] - [dependencies] -mod_interface = { workspace = true, features = ["full"] } -former = { workspace = true, features = ["full"] } -format_tools = { workspace = true, features = ["full"] } -reflect_tools = { workspace = true, features = [ "full" ] } -clap = { version = "4.5.20", features = ["derive"] } -tokio = { version = "1", features = ["full"] } google-sheets4 = "*" pth = "0.21.0" +clap = { version = "4.5", features = ["derive"] } +tokio = { version = "1", features = ["full"] } dotenv = "0.15" -serde = { version = "1.0.213", features = ["derive"] } +serde = "1.0.213" serde_with = "3.11.0" error_tools = "0.19.0" -derive_tools = { version = "0.32.0", features = ["full"] } +derive_tools = "0.32.0" +thiserror = "2.0.3" serde_json = "1.0.132" regex = "1.11.1" - -[dev-dependencies] -test_tools = { workspace = true } diff --git a/module/move/gspread/design/commands.md b/module/move/gspread/design/commands.md new file mode 100644 index 0000000000..cf79956a1c --- /dev/null +++ b/module/move/gspread/design/commands.md @@ -0,0 +1,27 @@ +# Commands + +## Legend +- `<...>` - argument. + +## Notations +- `A1 == Columns are denoted by letters (A, B, C, ...), + Rows are denoted by numbers (1, 2, 3, ...).` +- `R1C1 == R represents the row (Row), +C represents the column (Column)` + +### Header + +```shell +main gspread header --url --tab +``` + +### Rows +```shell +main gspread rows --url --tab +``` + +### Cell +```shell +main gspread cell get --url --tab --cel +main gspread cell set --url --tab --cel --val +``` diff --git a/module/move/gspread/src/commands/gspread_cells.rs b/module/move/gspread/src/commands/gspread_cells.rs index cd7a4cc555..17c230ee38 100644 --- a/module/move/gspread/src/commands/gspread_cells.rs +++ b/module/move/gspread/src/commands/gspread_cells.rs @@ -1,72 +1,72 @@ -//! -//! Cells commands. -//! set command -> set specified values in specified columns in specified row. -//! - -mod private -{ - use clap::Subcommand; - - use crate::*; - use actions::gspread::get_spreadsheet_id_from_url; - - #[ derive( Debug, Subcommand ) ] - pub enum Commands - { - #[ command( name = "set" ) ] - Set - { - #[ arg( long ) ] - select_row_by_key : String, - - #[ arg( long ) ] - json : String, - - #[ arg( long ) ] - url : String, - - #[ arg( long ) ] - tab : String - } - - } - - pub async fn command - ( - hub : &SheetsType, - commands : Commands - ) - { - match commands - { - Commands::Set { select_row_by_key, json, url, tab } => - { - let spreadsheet_id = get_spreadsheet_id_from_url( url.as_str() ).unwrap(); - - let result = actions::gspread_cells_set::action - ( - &hub, - select_row_by_key.as_str(), - json.as_str(), - spreadsheet_id, - tab.as_str() - ).await; - - match result - { - Ok( msg ) => println!( "{}", msg ), - Err( error ) => println!( "{}", error ) - } - } - } - } -} - -crate::mod_interface! -{ - own use - { - command, - Commands - }; +//! +//! Cells commands. +//! set command -> set specified values in specified columns in specified row. +//! + +mod private +{ + use clap::Subcommand; + + use crate::*; + use actions::gspread::get_spreadsheet_id_from_url; + + #[ derive( Debug, Subcommand ) ] + pub enum Commands + { + #[ command( name = "set" ) ] + Set + { + #[ arg( long ) ] + select_row_by_key : String, + + #[ arg( long ) ] + json : String, + + #[ arg( long ) ] + url : String, + + #[ arg( long ) ] + tab : String + } + + } + + pub async fn command + ( + hub : &SheetsType, + commands : Commands + ) + { + match commands + { + Commands::Set { select_row_by_key, json, url, tab } => + { + let spreadsheet_id = get_spreadsheet_id_from_url( url.as_str() ).unwrap(); + + let result = actions::gspread_cells_set::action + ( + &hub, + select_row_by_key.as_str(), + json.as_str(), + spreadsheet_id, + tab.as_str() + ).await; + + match result + { + Ok( msg ) => println!( "{}", msg ), + Err( error ) => println!( "{}", error ) + } + } + } + } +} + +crate::mod_interface! +{ + own use + { + command, + Commands + }; } \ No newline at end of file diff --git a/module/move/gspread/src/debug/table_wrapper.rs b/module/move/gspread/src/debug/table_wrapper.rs new file mode 100644 index 0000000000..cf008f977c --- /dev/null +++ b/module/move/gspread/src/debug/table_wrapper.rs @@ -0,0 +1,58 @@ +//! +//! Simple custom wrapper for outputting data to console +//! +//! It is used for "header" and "rows" commands +//! + + +mod private +{ + + use crate::*; + use ser::JsonValue; + use actions::gspread::Value; + + pub struct Table + { + pub data: Value, + } + + impl Table + { + pub fn new( data: Value ) -> Self + { + Table { data } + } + + pub fn display(&self) + { + for ( i, row ) in self.data.iter().enumerate() + { + print!( "row {}: ", i + 1 ); + for cell in row + { + print!( "{} ", Self::format_value( cell ) ); + } + println!(); + } + } + + fn format_value( value: &JsonValue ) -> String + { + match value + { + JsonValue::String( s ) => s.clone(), + JsonValue::Number( n ) => n.to_string(), + JsonValue::Bool( b ) => b.to_string(), + JsonValue::Null => "".to_string(), + _ => "unsupported".to_string(), + } + } + } + +} + +pub use private:: +{ + Table, +}; \ No newline at end of file diff --git a/module/move/gspread/src/lib.rs b/module/move/gspread/src/lib.rs index c0d2432985..55a2eaa551 100644 --- a/module/move/gspread/src/lib.rs +++ b/module/move/gspread/src/lib.rs @@ -1,9 +1,8 @@ -use mod_interface::mod_interface; -use error_tools::thiserror; - -mod private -{ -} +pub mod client; +pub mod secret; +pub mod commands; +pub mod actions; +mod debug; pub mod ser { @@ -12,30 +11,7 @@ pub mod ser Serialize, Deserialize, }; - pub use serde_json:: - { - value::{ Value as JsonValue, Number as JsonNumber }, - error::Error, - self - }; + pub use serde_json::value::Value as JsonValue; + pub use serde_json::value::Number as JsonNumber; pub use serde_with::*; -} - -crate::mod_interface! -{ - - layer client; - layer debug; - layer commands; - layer actions; - layer secret; - layer util; - - exposed use ::reflect_tools:: - { - Fields, - _IteratorTrait, - IteratorTrait, - }; - } \ No newline at end of file diff --git a/module/move/gspread/src/secret.rs b/module/move/gspread/src/secret.rs index f70792b958..9acac1e779 100644 --- a/module/move/gspread/src/secret.rs +++ b/module/move/gspread/src/secret.rs @@ -41,7 +41,7 @@ mod private #[ allow( non_snake_case ) ] pub struct Secret { - pub CLIENT_SECRET : String, + pub CLIENT_SECRET: String, pub CLIENT_ID: String, pub AUTH_URI : String, pub TOKEN_URI : String, @@ -137,23 +137,9 @@ Either define missing environment variable or make sure `./.key/-env.toml` file { let p = var( name, default )?; pth::AbsolutePath::from_paths( ( pth::CurrentPath, p ) ) - .map_err( |e| Error::VariableIllformed( name, e.to_string() ) ) + .map_err( |e| Error::VariableIllformed( name, e.to_string() ) ) } } -crate::mod_interface! -{ - - own use - { - Error, - Result, - }; - - orphan use - { - Secret, - }; - -} \ No newline at end of file +pub use private::Secret; \ No newline at end of file From 8ba106ae43abf4c041b31160660ae562badab7b8 Mon Sep 17 00:00:00 2001 From: vsevolod Date: Mon, 18 Nov 2024 20:18:53 +0100 Subject: [PATCH 2/8] format_tools, mod_interface and usage information added --- module/move/gspread/Cargo.toml | 16 ++++- module/move/gspread/design/commands.md | 8 +-- .../gspread/src/actions/gspread_get_rows.rs | 1 + .../move/gspread/src/debug/table_wrapper.rs | 58 ------------------- module/move/gspread/src/lib.rs | 30 ++++++++-- module/move/gspread/src/secret.rs | 16 ++++- 6 files changed, 59 insertions(+), 70 deletions(-) delete mode 100644 module/move/gspread/src/debug/table_wrapper.rs diff --git a/module/move/gspread/Cargo.toml b/module/move/gspread/Cargo.toml index e31800d872..4453d505d4 100644 --- a/module/move/gspread/Cargo.toml +++ b/module/move/gspread/Cargo.toml @@ -17,16 +17,28 @@ default-run = "main" name = "main" path = "src/bin/main.rs" +[features] +default = [ "enabled" ] +full = [ "enabled" ] +enabled = [ + "former/enabled", + "format_tools/enabled", + "reflect_tools/enabled", +] + [dependencies] +mod_interface = { workspace = true, features = ["full"] } +former = { workspace = true, features = ["full"] } +format_tools = { workspace = true, features = ["full"] } +reflect_tools = { workspace = true, features = [ "full" ] } google-sheets4 = "*" pth = "0.21.0" -clap = { version = "4.5", features = ["derive"] } +clap = { version = "4.5.20", features = ["derive"] } tokio = { version = "1", features = ["full"] } dotenv = "0.15" serde = "1.0.213" serde_with = "3.11.0" error_tools = "0.19.0" derive_tools = "0.32.0" -thiserror = "2.0.3" serde_json = "1.0.132" regex = "1.11.1" diff --git a/module/move/gspread/design/commands.md b/module/move/gspread/design/commands.md index cf79956a1c..7eaeaa5302 100644 --- a/module/move/gspread/design/commands.md +++ b/module/move/gspread/design/commands.md @@ -12,16 +12,16 @@ C represents the column (Column)` ### Header ```shell -main gspread header --url --tab +gspread header --url --tab ``` ### Rows ```shell -main gspread rows --url --tab +gspread rows --url --tab ``` ### Cell ```shell -main gspread cell get --url --tab --cel -main gspread cell set --url --tab --cel --val +gspread cell get --url --tab --cel +gspread cell set --url --tab --cel --val ``` diff --git a/module/move/gspread/src/actions/gspread_get_rows.rs b/module/move/gspread/src/actions/gspread_get_rows.rs index 3a083217ed..b3d3840d1d 100644 --- a/module/move/gspread/src/actions/gspread_get_rows.rs +++ b/module/move/gspread/src/actions/gspread_get_rows.rs @@ -8,6 +8,7 @@ mod private { use crate::*; + use debug::row_wrapper::RowWrapper; use client::SheetsType; use actions::gspread::Result; use ser::JsonValue; diff --git a/module/move/gspread/src/debug/table_wrapper.rs b/module/move/gspread/src/debug/table_wrapper.rs deleted file mode 100644 index cf008f977c..0000000000 --- a/module/move/gspread/src/debug/table_wrapper.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! -//! Simple custom wrapper for outputting data to console -//! -//! It is used for "header" and "rows" commands -//! - - -mod private -{ - - use crate::*; - use ser::JsonValue; - use actions::gspread::Value; - - pub struct Table - { - pub data: Value, - } - - impl Table - { - pub fn new( data: Value ) -> Self - { - Table { data } - } - - pub fn display(&self) - { - for ( i, row ) in self.data.iter().enumerate() - { - print!( "row {}: ", i + 1 ); - for cell in row - { - print!( "{} ", Self::format_value( cell ) ); - } - println!(); - } - } - - fn format_value( value: &JsonValue ) -> String - { - match value - { - JsonValue::String( s ) => s.clone(), - JsonValue::Number( n ) => n.to_string(), - JsonValue::Bool( b ) => b.to_string(), - JsonValue::Null => "".to_string(), - _ => "unsupported".to_string(), - } - } - } - -} - -pub use private:: -{ - Table, -}; \ No newline at end of file diff --git a/module/move/gspread/src/lib.rs b/module/move/gspread/src/lib.rs index 55a2eaa551..a646995766 100644 --- a/module/move/gspread/src/lib.rs +++ b/module/move/gspread/src/lib.rs @@ -1,8 +1,9 @@ -pub mod client; -pub mod secret; -pub mod commands; -pub mod actions; -mod debug; +use mod_interface::mod_interface; +use error_tools::thiserror; + +mod private +{ +} pub mod ser { @@ -14,4 +15,23 @@ pub mod ser pub use serde_json::value::Value as JsonValue; pub use serde_json::value::Number as JsonNumber; pub use serde_with::*; +} + +crate::mod_interface! +{ + + layer client; + layer debug; + layer commands; + layer actions; + layer secret; + layer util; + + exposed use ::reflect_tools:: + { + Fields, + _IteratorTrait, + IteratorTrait, + }; + } \ No newline at end of file diff --git a/module/move/gspread/src/secret.rs b/module/move/gspread/src/secret.rs index 9acac1e779..99ba3f9f9d 100644 --- a/module/move/gspread/src/secret.rs +++ b/module/move/gspread/src/secret.rs @@ -142,4 +142,18 @@ Either define missing environment variable or make sure `./.key/-env.toml` file } -pub use private::Secret; \ No newline at end of file +crate::mod_interface! +{ + + own use + { + Error, + Result, + }; + + orphan use + { + Secret, + }; + +} \ No newline at end of file From 874ed0d996e90667524de365b79db20e81f85821 Mon Sep 17 00:00:00 2001 From: vsevolod Date: Thu, 21 Nov 2024 20:20:31 +0100 Subject: [PATCH 3/8] formating fixed --- module/move/gspread/Cargo.toml | 8 ++++---- module/move/gspread/src/secret.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/module/move/gspread/Cargo.toml b/module/move/gspread/Cargo.toml index 4453d505d4..f2fe39c5b2 100644 --- a/module/move/gspread/Cargo.toml +++ b/module/move/gspread/Cargo.toml @@ -31,14 +31,14 @@ mod_interface = { workspace = true, features = ["full"] } former = { workspace = true, features = ["full"] } format_tools = { workspace = true, features = ["full"] } reflect_tools = { workspace = true, features = [ "full" ] } -google-sheets4 = "*" -pth = "0.21.0" clap = { version = "4.5.20", features = ["derive"] } tokio = { version = "1", features = ["full"] } +google-sheets4 = "*" +pth = "0.21.0" dotenv = "0.15" -serde = "1.0.213" +serde = { version = "1.0.213", features = ["derive"] } serde_with = "3.11.0" error_tools = "0.19.0" -derive_tools = "0.32.0" +derive_tools = { version = "0.32.0", features = ["full"] } serde_json = "1.0.132" regex = "1.11.1" diff --git a/module/move/gspread/src/secret.rs b/module/move/gspread/src/secret.rs index 99ba3f9f9d..3aab2bc1ac 100644 --- a/module/move/gspread/src/secret.rs +++ b/module/move/gspread/src/secret.rs @@ -41,7 +41,7 @@ mod private #[ allow( non_snake_case ) ] pub struct Secret { - pub CLIENT_SECRET: String, + pub CLIENT_SECRET : String, pub CLIENT_ID: String, pub AUTH_URI : String, pub TOKEN_URI : String, From 13299b5ede7e500332b28848e82278c4ea8793f0 Mon Sep 17 00:00:00 2001 From: vsevolod Date: Thu, 21 Nov 2024 20:34:44 +0100 Subject: [PATCH 4/8] formating fixed --- module/move/gspread/src/secret.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/move/gspread/src/secret.rs b/module/move/gspread/src/secret.rs index 3aab2bc1ac..f70792b958 100644 --- a/module/move/gspread/src/secret.rs +++ b/module/move/gspread/src/secret.rs @@ -137,7 +137,7 @@ Either define missing environment variable or make sure `./.key/-env.toml` file { let p = var( name, default )?; pth::AbsolutePath::from_paths( ( pth::CurrentPath, p ) ) - .map_err( |e| Error::VariableIllformed( name, e.to_string() ) ) + .map_err( |e| Error::VariableIllformed( name, e.to_string() ) ) } } From a8526ccfe6c4f80746aa0b3058bd30ae33e88d9a Mon Sep 17 00:00:00 2001 From: vsevolod Date: Sun, 24 Nov 2024 17:37:38 +0100 Subject: [PATCH 5/8] tests added, debug dir removed, output fixed --- module/move/gspread/Cargo.toml | 3 +++ module/move/gspread/design/commands.md | 27 ------------------- .../gspread/src/actions/gspread_get_rows.rs | 1 - 3 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 module/move/gspread/design/commands.md diff --git a/module/move/gspread/Cargo.toml b/module/move/gspread/Cargo.toml index f2fe39c5b2..7d75b04122 100644 --- a/module/move/gspread/Cargo.toml +++ b/module/move/gspread/Cargo.toml @@ -42,3 +42,6 @@ error_tools = "0.19.0" derive_tools = { version = "0.32.0", features = ["full"] } serde_json = "1.0.132" regex = "1.11.1" + +[dev-dependencies] +test_tools = { workspace = true } diff --git a/module/move/gspread/design/commands.md b/module/move/gspread/design/commands.md deleted file mode 100644 index 7eaeaa5302..0000000000 --- a/module/move/gspread/design/commands.md +++ /dev/null @@ -1,27 +0,0 @@ -# Commands - -## Legend -- `<...>` - argument. - -## Notations -- `A1 == Columns are denoted by letters (A, B, C, ...), - Rows are denoted by numbers (1, 2, 3, ...).` -- `R1C1 == R represents the row (Row), -C represents the column (Column)` - -### Header - -```shell -gspread header --url --tab -``` - -### Rows -```shell -gspread rows --url --tab -``` - -### Cell -```shell -gspread cell get --url --tab --cel -gspread cell set --url --tab --cel --val -``` diff --git a/module/move/gspread/src/actions/gspread_get_rows.rs b/module/move/gspread/src/actions/gspread_get_rows.rs index b3d3840d1d..3a083217ed 100644 --- a/module/move/gspread/src/actions/gspread_get_rows.rs +++ b/module/move/gspread/src/actions/gspread_get_rows.rs @@ -8,7 +8,6 @@ mod private { use crate::*; - use debug::row_wrapper::RowWrapper; use client::SheetsType; use actions::gspread::Result; use ser::JsonValue; From 00f4e280fbcb5b9dfa05ca92338d46eaba8db7ab Mon Sep 17 00:00:00 2001 From: Vsevolod Date: Tue, 3 Dec 2024 16:09:09 +0100 Subject: [PATCH 6/8] cells command were added --- module/move/gspread/src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/module/move/gspread/src/lib.rs b/module/move/gspread/src/lib.rs index a646995766..2e4b049807 100644 --- a/module/move/gspread/src/lib.rs +++ b/module/move/gspread/src/lib.rs @@ -12,8 +12,14 @@ pub mod ser Serialize, Deserialize, }; - pub use serde_json::value::Value as JsonValue; - pub use serde_json::value::Number as JsonNumber; + // pub use serde_json::value::Value as JsonValue; + // pub use serde_json::value::Number as JsonNumber; + pub use serde_json:: + { + value::{ Value as JsonValue, Number as JsonNumber }, + error::Error, + self + }; pub use serde_with::*; } From 3602e6da4a489d412d8dc1c56cd75c82d04d0f77 Mon Sep 17 00:00:00 2001 From: Vsevolod Date: Tue, 3 Dec 2024 17:17:33 +0100 Subject: [PATCH 7/8] format fixed --- module/move/gspread/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/module/move/gspread/src/lib.rs b/module/move/gspread/src/lib.rs index 2e4b049807..c0d2432985 100644 --- a/module/move/gspread/src/lib.rs +++ b/module/move/gspread/src/lib.rs @@ -12,8 +12,6 @@ pub mod ser Serialize, Deserialize, }; - // pub use serde_json::value::Value as JsonValue; - // pub use serde_json::value::Number as JsonNumber; pub use serde_json:: { value::{ Value as JsonValue, Number as JsonNumber }, From 439254482b1bf102cab7f28e3920bb344430aaf2 Mon Sep 17 00:00:00 2001 From: Vsevolod Date: Wed, 4 Dec 2024 12:02:04 +0100 Subject: [PATCH 8/8] file fix --- module/core/process_tools/src/process.rs | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/module/core/process_tools/src/process.rs b/module/core/process_tools/src/process.rs index d11e5c3d16..bcb7ad6936 100644 --- a/module/core/process_tools/src/process.rs +++ b/module/core/process_tools/src/process.rs @@ -234,22 +234,22 @@ mod private // # Returns: // A `Result` containing a `Report` on success, which includes the command's output, // or an error if the command fails to execute or complete. - // pub fn run_with_shell( self, exec_path : &str, ) -> Result< Report, Report > - // { - // let ( program, args ) = - // if cfg!( target_os = "windows" ) - // { - // ( "gspread", [ "/C", exec_path ] ) - // } - // else - // { - // ( "sh", [ "-c", exec_path ] ) - // }; - // self - // .args( args.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) - // .bin_path( program ) - // .run() - // } + pub fn run_with_shell( self, exec_path : &str, ) -> Result< Report, Report > + { + let ( program, args ) = + if cfg!( target_os = "windows" ) + { + ( "cmd", [ "/C", exec_path ] ) + } + else + { + ( "sh", [ "-c", exec_path ] ) + }; + self + .args( args.into_iter().map( OsString::from ).collect::< Vec< _ > >() ) + .bin_path( program ) + .run() + } } /// Process command output.