From b3c719a3b7c05319e517449f4f878ed57cf1e6bc Mon Sep 17 00:00:00 2001 From: miyake13000 Date: Thu, 26 Sep 2024 08:26:46 +0900 Subject: [PATCH 1/7] Add rask-cli --- rask-cli/.gitignore | 1 + rask-cli/Cargo.lock | 1206 +++++++++++++++++++++++++++++ rask-cli/Cargo.toml | 19 + rask-cli/LICENSE | 21 + rask-cli/README.md | 38 + rask-cli/src/bin/rask-cli/args.rs | 80 ++ rask-cli/src/bin/rask-cli/main.rs | 57 ++ rask-cli/src/client.rs | 56 ++ rask-cli/src/lib.rs | 48 ++ rask-cli/src/project.rs | 37 + rask-cli/src/task.rs | 87 +++ rask-cli/src/user.rs | 36 + 12 files changed, 1686 insertions(+) create mode 100644 rask-cli/.gitignore create mode 100644 rask-cli/Cargo.lock create mode 100644 rask-cli/Cargo.toml create mode 100644 rask-cli/LICENSE create mode 100644 rask-cli/README.md create mode 100644 rask-cli/src/bin/rask-cli/args.rs create mode 100644 rask-cli/src/bin/rask-cli/main.rs create mode 100644 rask-cli/src/client.rs create mode 100644 rask-cli/src/lib.rs create mode 100644 rask-cli/src/project.rs create mode 100644 rask-cli/src/task.rs create mode 100644 rask-cli/src/user.rs diff --git a/rask-cli/.gitignore b/rask-cli/.gitignore new file mode 100644 index 00000000..ea8c4bf7 --- /dev/null +++ b/rask-cli/.gitignore @@ -0,0 +1 @@ +/target diff --git a/rask-cli/Cargo.lock b/rask-cli/Cargo.lock new file mode 100644 index 00000000..cdcb9b06 --- /dev/null +++ b/rask-cli/Cargo.lock @@ -0,0 +1,1206 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "anstream" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + +[[package]] +name = "anstyle-parse" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + +[[package]] +name = "cc" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" + +[[package]] +name = "colorchoice" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gimli" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" + +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "ipnet" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "object" +version = "0.36.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fe68c2e9e1a1234e218683dbdf9f9dfcb094113c5ac2b938dfcb9bab4c4140b" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.59.0", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rask" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "reqwest", + "serde", + "thiserror", +] + +[[package]] +name = "reqwest" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pemfile", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + +[[package]] +name = "rustls" +version = "0.23.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64", + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] + +[[package]] +name = "thiserror" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" + +[[package]] +name = "web-sys" +version = "0.3.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/rask-cli/Cargo.toml b/rask-cli/Cargo.toml new file mode 100644 index 00000000..91ebb4e9 --- /dev/null +++ b/rask-cli/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "rask" +version = "0.1.0" +edition = "2021" +authors = ["nomlab [https://github.com/nomlab]"] +description = "Library for communicate with Rask" +readme = "README.md" +license = "MIT" +license-file = "LICENSE" + +[[bin]] +name = "rask-cli" + +[dependencies] +anyhow = "1.0" +clap = { version = "4", features = ["derive", "env"] } +reqwest = { version = "0.12", features = ["blocking", "json", "rustls-tls"], default-features = false } +serde = { version = "1.0", features = ["derive"] } +thiserror = "1.0" diff --git a/rask-cli/LICENSE b/rask-cli/LICENSE new file mode 100644 index 00000000..05d9232c --- /dev/null +++ b/rask-cli/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 nomlab + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/rask-cli/README.md b/rask-cli/README.md new file mode 100644 index 00000000..c5c01e3a --- /dev/null +++ b/rask-cli/README.md @@ -0,0 +1,38 @@ +# rask-cli +CLI tool to manage Rask + +## Install +You can install [release page](./releases/latest) + +Or, build from source +1. Clone this repository +2. Install Rust +3. Build (`cargo build --release`) +4. You can install Binary (`./target/release/rask-cli`) to wherever you want + +## Usage +* Show all Tasks / Users / Projects + ```bash + $ ./rask-cli task list + $ ./rask-cli user list + $ ./rask-cli projects list + ``` +* Create new Task + ```bash + $ ./rask-cli task create --title \ + --assigner-name <ASSIGNER_NAME> \ + --state <todo/done/someday> \ + --project-name <PROJECT_NAME> \ + --due_at <DATE> \ + --description <DESCRIPTION> + ``` + * Ex: + ```bash + $ ./rask-cli task create --title "Complete my measurement" \ + --assigner-name "nomlab" \ + --state todo \ + --project-name "My Research" \ + --due_at "2024-09-26" \ + --description "See http://example.com for details" + ``` +* Show `rask-cli --help` for more details diff --git a/rask-cli/src/bin/rask-cli/args.rs b/rask-cli/src/bin/rask-cli/args.rs new file mode 100644 index 00000000..1758fe29 --- /dev/null +++ b/rask-cli/src/bin/rask-cli/args.rs @@ -0,0 +1,80 @@ +use clap::Parser; +use rask::task::TaskState; + +#[derive(Debug, Parser)] +#[command(author, version, about)] +pub struct Args { + /// API Key for communicate with Rask + #[arg(short, long, required = true, env = "RASK_API_KEY")] + pub api_key: String, + + /// API Key for communicate with Rask + #[arg(short, long, required = true, env = "RASK_URL")] + pub url: String, + + #[command(subcommand)] + pub target: Target, +} + +#[derive(Debug, Parser)] +pub enum Target { + /// Manage tasks + #[command(subcommand)] + Task(TaskAction), + + /// Manage users + #[command(subcommand)] + User(UserAction), + + /// Manage projects + #[command(subcommand)] + Project(ProjectAction), +} + +#[derive(Debug, Parser)] +pub enum TaskAction { + /// Create new task + Create(TaskCreateArgs), + + /// List tasks + List, +} + +#[derive(Debug, Parser)] +pub enum UserAction { + /// List users + List, +} + +#[derive(Debug, Parser)] +pub enum ProjectAction { + /// List projects + List, +} + +#[derive(Debug, Parser)] +pub struct TaskCreateArgs { + /// Title for new task. Ex: "Awesome Task" + #[arg(short, long)] + pub title: String, + + /// State of new task. + #[arg(short, long, default_value = "todo")] + pub state: TaskState, + + /// Assigner name of new task. Ex: "john" + #[arg(short, long)] + pub assigner_name: String, + + /// Project name that new task is assigned. Ex: "Grateful project" + #[arg(short, long)] + pub project_name: Option<String>, + + /// Dead line of new task. Ex: "2036/2/6" or "2036-2-6" + #[arg(short = 't', long)] + pub due_at: Option<String>, + + /// Description of new task. Ex: "Do something" + #[arg(short, long)] + pub description: Option<String>, +} diff --git a/rask-cli/src/bin/rask-cli/main.rs b/rask-cli/src/bin/rask-cli/main.rs new file mode 100644 index 00000000..634cd086 --- /dev/null +++ b/rask-cli/src/bin/rask-cli/main.rs @@ -0,0 +1,57 @@ +mod args; + +use anyhow::{Context, Result}; +use args::*; +use clap::Parser; +use rask::project::*; +use rask::task::*; +use rask::user::*; +use rask::Rask; + +fn main() -> Result<()> { + let args = Args::parse(); + + Rask::init(args.url, args.api_key); + + match args.target { + Target::Task(action) => match action { + TaskAction::Create(args) => { + let new_task = TaskRequest::new( + args.title, + args.state, + args.assigner_name, + args.project_name, + args.due_at, + args.description, + ) + .context("Failed to create new task")?; + Task::save(new_task).context("Failed to save new task")?; + println!("Success to add new task"); + } + TaskAction::List => { + let tasks = Task::list().context("Failed to get Task list")?; + for task in tasks { + println!("{:?}", task); + } + } + }, + Target::User(action) => match action { + UserAction::List => { + let users = User::list().context("Failed to get User list")?; + for user in users { + println!("{:?}", user); + } + } + }, + Target::Project(action) => match action { + ProjectAction::List => { + let projects = Project::list().context("Failed to get Project list")?; + for project in projects { + println!("{:?}", project); + } + } + }, + } + + Ok(()) +} diff --git a/rask-cli/src/client.rs b/rask-cli/src/client.rs new file mode 100644 index 00000000..394d9150 --- /dev/null +++ b/rask-cli/src/client.rs @@ -0,0 +1,56 @@ +use crate::{Error, Result}; +use reqwest::blocking::Client; +pub use reqwest::blocking::Response; +pub use reqwest::Method; +use reqwest::Url; +use serde::Serialize; + +#[derive(Debug, Clone)] +pub struct RawClient { + url: Url, + key: String, +} + +impl RawClient { + pub fn new<S1, S2>(url: S1, key: S2) -> Result<Self> + where + S1: AsRef<str>, + S2: Into<String>, + { + let url = Url::parse(url.as_ref()).map_err(|e| Error::UrlParse(e.to_string()))?; + Ok(Self { + url, + key: key.into(), + }) + } + + pub fn get<S: AsRef<str>>(&self, path: S) -> Result<Response> { + self.send_request(Method::GET, path, Option::<()>::None) + } + + pub fn send_request<S, R>(&self, method: Method, path: S, body: Option<R>) -> Result<Response> + where + S: AsRef<str>, + R: Serialize, + { + let res = Client::new() + .request( + method.clone(), + self.url + .join(path.as_ref()) + .map_err(|e| Error::UrlParse(e.to_string()))?, + ) + .query(&[("api_token", &self.key)]) + .json(&body) + .send()?; + + match res.status().as_u16() { + 200..=299 => Ok(res), + _ => Err(Error::API( + method.to_string(), + res.status().to_string(), + res.text().unwrap_or("Failed to show body".to_string()), + )), + } + } +} diff --git a/rask-cli/src/lib.rs b/rask-cli/src/lib.rs new file mode 100644 index 00000000..697cdd8a --- /dev/null +++ b/rask-cli/src/lib.rs @@ -0,0 +1,48 @@ +mod client; +pub mod project; +pub mod task; +pub mod user; + +use client::RawClient; +use serde::{Deserialize, Serialize}; +use std::sync::OnceLock; +use thiserror::Error; + +static RASK_CLIENT: OnceLock<RawClient> = OnceLock::new(); + +#[derive(Debug)] +pub struct Rask; + +impl Rask { + pub fn init<S1, S2>(url: S1, key: S2) + where + S1: AsRef<str>, + S2: Into<String>, + { + RASK_CLIENT.get_or_init(|| client::RawClient::new(url, key).unwrap()); + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct IdNameSet { + id: usize, + name: String, +} + +#[derive(Debug, Error)] +pub enum Error { + #[error("Rask client not initialized")] + NotInitialized, + #[error(transparent)] + Network(#[from] reqwest::Error), + #[error("Failed to decode response json: {0}")] + JsonDecode(String), + #[error("Not found: \"{0}\" from \"{1}\"")] + NotFound(String, String), + #[error("Failed to Parse URL: {0}")] + UrlParse(String), + #[error("Failed to {0} data, satus: {1}, body: {2}")] + API(String, String, String), +} + +type Result<T> = std::result::Result<T, Error>; diff --git a/rask-cli/src/project.rs b/rask-cli/src/project.rs new file mode 100644 index 00000000..35cd6e49 --- /dev/null +++ b/rask-cli/src/project.rs @@ -0,0 +1,37 @@ +use crate::{Error, Result}; +use crate::{IdNameSet, RASK_CLIENT}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug)] +pub struct Project; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ProjectResponse { + pub id: usize, + pub name: String, + pub created_at: String, + pub updated_at: String, + pub user: IdNameSet, + pub url: String, +} + +impl Project { + pub fn list() -> Result<Vec<ProjectResponse>> { + let client = RASK_CLIENT.get().ok_or(Error::NotInitialized)?; + client + .get("projects.json")? + .json() + .map_err(|e| Error::JsonDecode(e.to_string())) + } + + pub fn find_by_name<S: AsRef<str>>(name: S) -> Result<ProjectResponse> { + let projects = Self::list()?; + projects + .into_iter() + .find(|i| i.name == name.as_ref()) + .ok_or(Error::NotFound( + name.as_ref().to_string(), + "Project".to_string(), + )) + } +} diff --git a/rask-cli/src/task.rs b/rask-cli/src/task.rs new file mode 100644 index 00000000..dcd68135 --- /dev/null +++ b/rask-cli/src/task.rs @@ -0,0 +1,87 @@ +use crate::client::Method; +use crate::project::Project; +use crate::user::User; +use crate::{Error, Result}; +use crate::{IdNameSet, RASK_CLIENT}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug)] +pub struct Task; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TaskRequest { + content: String, + task_state_id: usize, + assigner_id: usize, + project_id: Option<usize>, + due_at: Option<String>, + description: Option<String>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TaskResponse { + pub id: usize, + pub content: String, + pub state: Option<TaskState>, + pub description: Option<String>, + pub deu_at: Option<String>, + pub created_at: String, + pub updated_at: String, + pub creator: IdNameSet, + pub assigner: IdNameSet, + pub project: Option<IdNameSet>, + pub url: String, +} + +#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, clap::ValueEnum)] +pub enum TaskState { + #[default] + Todo = 1, + Done = 2, + Someday = 3, +} + +impl Task { + pub fn list() -> Result<Vec<TaskResponse>> { + let client = RASK_CLIENT.get().ok_or(Error::NotInitialized)?; + client + .get("tasks.json")? + .json() + .map_err(|e| Error::JsonDecode(e.to_string())) + } + + pub fn save(data: TaskRequest) -> Result<()> { + let client = RASK_CLIENT.get().ok_or(Error::NotInitialized)?; + let _ = client.send_request(Method::POST, "tasks.json", Some(data))?; + Ok(()) + } +} + +impl TaskRequest { + pub fn new<S1, S2>( + title: String, + state: TaskState, + assigner: S1, + project: Option<S2>, + due_at: Option<String>, + description: Option<String>, + ) -> Result<Self> + where + S1: AsRef<str>, + S2: AsRef<str>, + { + let assigner_id = User::find_by_name(assigner)?.id; + let project_id = match project { + Some(p) => Some(Project::find_by_name(p)?.id), + None => None, + }; + Ok(Self { + content: title, + task_state_id: state as usize, + assigner_id, + project_id, + due_at, + description, + }) + } +} diff --git a/rask-cli/src/user.rs b/rask-cli/src/user.rs new file mode 100644 index 00000000..d35a687f --- /dev/null +++ b/rask-cli/src/user.rs @@ -0,0 +1,36 @@ +use crate::RASK_CLIENT; +use crate::{Error, Result}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug)] +pub struct User; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UserResponse { + pub id: usize, + pub name: String, + pub created_at: String, + pub updated_at: String, + pub url: String, +} + +impl User { + pub fn list() -> Result<Vec<UserResponse>> { + let client = RASK_CLIENT.get().ok_or(Error::NotInitialized)?; + client + .get("users.json")? + .json() + .map_err(|e| Error::JsonDecode(e.to_string())) + } + + pub fn find_by_name<S: AsRef<str>>(name: S) -> Result<UserResponse> { + let users = Self::list()?; + users + .into_iter() + .find(|i| i.name == name.as_ref()) + .ok_or(Error::NotFound( + name.as_ref().to_string(), + "User".to_string(), + )) + } +} From 50d133e1e024d11c02469b925517767abca8ba7b Mon Sep 17 00:00:00 2001 From: miyake13000 <miyake2020@s.okayama-u.ac.jp> Date: Thu, 26 Sep 2024 08:33:23 +0900 Subject: [PATCH 2/7] Fix LICENSE filed --- rask-cli/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/rask-cli/Cargo.toml b/rask-cli/Cargo.toml index 91ebb4e9..bf4ac7a2 100644 --- a/rask-cli/Cargo.toml +++ b/rask-cli/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" authors = ["nomlab [https://github.com/nomlab]"] description = "Library for communicate with Rask" readme = "README.md" -license = "MIT" license-file = "LICENSE" [[bin]] From c5b1aab66f116902ad4ae519ef1ee7c87410cc1e Mon Sep 17 00:00:00 2001 From: miyake13000 <miyake2020@s.okayama-u.ac.jp> Date: Thu, 26 Sep 2024 08:42:48 +0900 Subject: [PATCH 3/7] Update README --- rask-cli/README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rask-cli/README.md b/rask-cli/README.md index c5c01e3a..0fb21aa4 100644 --- a/rask-cli/README.md +++ b/rask-cli/README.md @@ -11,11 +11,21 @@ Or, build from source 4. You can install Binary (`./target/release/rask-cli`) to wherever you want ## Usage +* First, get Rask API token and set env variable + ```bash + $ export RASK_API_KEY="rask-thisissample-apitoken-012345679" + $ export RASK_URL="https://rask.example.com" + ``` + * Or, you must set above value when you run command + ```bash + $ rask-cli --api-key "rask-thisissample-apitoken-012345679" --url "https://rask.example.com" task list + ``` + * Show all Tasks / Users / Projects ```bash - $ ./rask-cli task list - $ ./rask-cli user list - $ ./rask-cli projects list + $ rask-cli task list + $ rask-cli user list + $ rask-cli projects list ``` * Create new Task ```bash @@ -28,7 +38,7 @@ Or, build from source ``` * Ex: ```bash - $ ./rask-cli task create --title "Complete my measurement" \ + $ rask-cli task create --title "Complete my measurement" \ --assigner-name "nomlab" \ --state todo \ --project-name "My Research" \ From c22d28d3084a23bc43974a23eb7a2faa2294c54a Mon Sep 17 00:00:00 2001 From: miyake13000 <miyake2020@s.okayama-u.ac.jp> Date: Mon, 23 Feb 2026 18:05:09 +0900 Subject: [PATCH 4/7] Add module for ApiToken model --- rask-cli/src/api_token.rs | 50 +++++++++++++++++++++++++++++++++++++++ rask-cli/src/lib.rs | 1 + 2 files changed, 51 insertions(+) create mode 100644 rask-cli/src/api_token.rs diff --git a/rask-cli/src/api_token.rs b/rask-cli/src/api_token.rs new file mode 100644 index 00000000..b0470e39 --- /dev/null +++ b/rask-cli/src/api_token.rs @@ -0,0 +1,50 @@ +use crate::client::Method; +use crate::{Error, IdNameSet, Result, RASK_CLIENT}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug)] +pub struct ApiToken; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ApiTokenRequest { + pub description: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ApiTokenResponse { + pub id: usize, + pub secret: String, + pub description: String, + pub expired_at: String, + pub created_at: String, + pub updated_at: String, + user: IdNameSet, + url: String, +} + +impl ApiToken { + pub fn save(data: ApiTokenRequest) -> Result<ApiTokenResponse> { + let client = RASK_CLIENT.get().ok_or(Error::NotInitialized)?; + let res = client.send_request(Method::POST, "api_tokens.json", Some(data))?; + res.json().map_err(|e| Error::JsonDecode(e.to_string())) + } + + pub fn list() -> Result<Vec<ApiTokenResponse>> { + let client = RASK_CLIENT.get().ok_or(Error::NotInitialized)?; + client + .get("users.json")? + .json() + .map_err(|e| Error::JsonDecode(e.to_string())) + } + + pub fn find_by_name<S: AsRef<str>>(name: S) -> Result<UserResponse> { + let users = Self::list()?; + users + .into_iter() + .find(|i| i.name == name.as_ref()) + .ok_or(Error::NotFound( + name.as_ref().to_string(), + "User".to_string(), + )) + } +} diff --git a/rask-cli/src/lib.rs b/rask-cli/src/lib.rs index 697cdd8a..68a9b37a 100644 --- a/rask-cli/src/lib.rs +++ b/rask-cli/src/lib.rs @@ -1,3 +1,4 @@ +pub mod api_token; mod client; pub mod project; pub mod task; From 83afec9c1525709a961f84b548145f472e87f0c0 Mon Sep 17 00:00:00 2001 From: miyake13000 <miyake2020@s.okayama-u.ac.jp> Date: Tue, 10 Mar 2026 15:30:06 +0900 Subject: [PATCH 5/7] Remove unexpected code and typo --- rask-cli/src/api_token.rs | 11 ----------- rask-cli/src/task.rs | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/rask-cli/src/api_token.rs b/rask-cli/src/api_token.rs index b0470e39..ff37a55e 100644 --- a/rask-cli/src/api_token.rs +++ b/rask-cli/src/api_token.rs @@ -36,15 +36,4 @@ impl ApiToken { .json() .map_err(|e| Error::JsonDecode(e.to_string())) } - - pub fn find_by_name<S: AsRef<str>>(name: S) -> Result<UserResponse> { - let users = Self::list()?; - users - .into_iter() - .find(|i| i.name == name.as_ref()) - .ok_or(Error::NotFound( - name.as_ref().to_string(), - "User".to_string(), - )) - } } diff --git a/rask-cli/src/task.rs b/rask-cli/src/task.rs index dcd68135..ffa7b62a 100644 --- a/rask-cli/src/task.rs +++ b/rask-cli/src/task.rs @@ -24,7 +24,7 @@ pub struct TaskResponse { pub content: String, pub state: Option<TaskState>, pub description: Option<String>, - pub deu_at: Option<String>, + pub due_at: Option<String>, pub created_at: String, pub updated_at: String, pub creator: IdNameSet, From 4cf568fb94b90abe6b974c95e53cd8e2e743e693 Mon Sep 17 00:00:00 2001 From: miyake13000 <miyake2020@s.okayama-u.ac.jp> Date: Fri, 13 Mar 2026 17:15:23 +0900 Subject: [PATCH 6/7] Change dir name: rask-cli to cli --- {rask-cli => cli}/.gitignore | 0 {rask-cli => cli}/Cargo.lock | 0 {rask-cli => cli}/Cargo.toml | 0 {rask-cli => cli}/LICENSE | 0 {rask-cli => cli}/README.md | 0 {rask-cli => cli}/src/api_token.rs | 0 {rask-cli => cli}/src/bin/rask-cli/args.rs | 0 {rask-cli => cli}/src/bin/rask-cli/main.rs | 0 {rask-cli => cli}/src/client.rs | 0 {rask-cli => cli}/src/lib.rs | 0 {rask-cli => cli}/src/project.rs | 0 {rask-cli => cli}/src/task.rs | 0 {rask-cli => cli}/src/user.rs | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename {rask-cli => cli}/.gitignore (100%) rename {rask-cli => cli}/Cargo.lock (100%) rename {rask-cli => cli}/Cargo.toml (100%) rename {rask-cli => cli}/LICENSE (100%) rename {rask-cli => cli}/README.md (100%) rename {rask-cli => cli}/src/api_token.rs (100%) rename {rask-cli => cli}/src/bin/rask-cli/args.rs (100%) rename {rask-cli => cli}/src/bin/rask-cli/main.rs (100%) rename {rask-cli => cli}/src/client.rs (100%) rename {rask-cli => cli}/src/lib.rs (100%) rename {rask-cli => cli}/src/project.rs (100%) rename {rask-cli => cli}/src/task.rs (100%) rename {rask-cli => cli}/src/user.rs (100%) diff --git a/rask-cli/.gitignore b/cli/.gitignore similarity index 100% rename from rask-cli/.gitignore rename to cli/.gitignore diff --git a/rask-cli/Cargo.lock b/cli/Cargo.lock similarity index 100% rename from rask-cli/Cargo.lock rename to cli/Cargo.lock diff --git a/rask-cli/Cargo.toml b/cli/Cargo.toml similarity index 100% rename from rask-cli/Cargo.toml rename to cli/Cargo.toml diff --git a/rask-cli/LICENSE b/cli/LICENSE similarity index 100% rename from rask-cli/LICENSE rename to cli/LICENSE diff --git a/rask-cli/README.md b/cli/README.md similarity index 100% rename from rask-cli/README.md rename to cli/README.md diff --git a/rask-cli/src/api_token.rs b/cli/src/api_token.rs similarity index 100% rename from rask-cli/src/api_token.rs rename to cli/src/api_token.rs diff --git a/rask-cli/src/bin/rask-cli/args.rs b/cli/src/bin/rask-cli/args.rs similarity index 100% rename from rask-cli/src/bin/rask-cli/args.rs rename to cli/src/bin/rask-cli/args.rs diff --git a/rask-cli/src/bin/rask-cli/main.rs b/cli/src/bin/rask-cli/main.rs similarity index 100% rename from rask-cli/src/bin/rask-cli/main.rs rename to cli/src/bin/rask-cli/main.rs diff --git a/rask-cli/src/client.rs b/cli/src/client.rs similarity index 100% rename from rask-cli/src/client.rs rename to cli/src/client.rs diff --git a/rask-cli/src/lib.rs b/cli/src/lib.rs similarity index 100% rename from rask-cli/src/lib.rs rename to cli/src/lib.rs diff --git a/rask-cli/src/project.rs b/cli/src/project.rs similarity index 100% rename from rask-cli/src/project.rs rename to cli/src/project.rs diff --git a/rask-cli/src/task.rs b/cli/src/task.rs similarity index 100% rename from rask-cli/src/task.rs rename to cli/src/task.rs diff --git a/rask-cli/src/user.rs b/cli/src/user.rs similarity index 100% rename from rask-cli/src/user.rs rename to cli/src/user.rs From 32d32e50cdc1b7d4d6f990ca3de9f0d4005823b0 Mon Sep 17 00:00:00 2001 From: miyake13000 <miyake2020@s.okayama-u.ac.jp> Date: Fri, 13 Mar 2026 17:20:19 +0900 Subject: [PATCH 7/7] Fix README for cli --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7e8b4f40..4fd1bc31 100644 --- a/README.md +++ b/README.md @@ -180,3 +180,7 @@ rask の開発には docker-compose を使用する. ```bash sudo systemctl enable rask-autoupdate.timer ``` + +## [CLI](./cli) +* Rask の API を利用してコマンドラインから Rask を操作できる CLI ツール +* 詳細は [こちら](./cli/README.md)