From 2174b42cff356d8230c899e8b025be35e6302cb7 Mon Sep 17 00:00:00 2001 From: Ciphercat <78522797+0xrsydn@users.noreply.github.com> Date: Thu, 5 Mar 2026 17:54:52 +0000 Subject: [PATCH] feat: implement idx-cli MVP foundation, provider abstraction, and core quote/history commands --- .gitignore | 5 + Cargo.lock | 1675 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 21 + src/api/mod.rs | 85 +++ src/api/types.rs | 84 +++ src/api/yahoo.rs | 259 +++++++ src/cache.rs | 1 + src/cli/cache.rs | 13 + src/cli/config.rs | 15 + src/cli/mod.rs | 38 + src/cli/stocks.rs | 51 ++ src/config.rs | 121 ++++ src/error.rs | 69 ++ src/main.rs | 54 ++ src/output/json.rs | 9 + src/output/mod.rs | 44 ++ src/output/table.rs | 80 +++ tests/cli.rs | 54 ++ 18 files changed, 2678 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/api/mod.rs create mode 100644 src/api/types.rs create mode 100644 src/api/yahoo.rs create mode 100644 src/cache.rs create mode 100644 src/cli/cache.rs create mode 100644 src/cli/config.rs create mode 100644 src/cli/mod.rs create mode 100644 src/cli/stocks.rs create mode 100644 src/config.rs create mode 100644 src/error.rs create mode 100644 src/main.rs create mode 100644 src/output/json.rs create mode 100644 src/output/mod.rs create mode 100644 src/output/table.rs create mode 100644 tests/cli.rs diff --git a/.gitignore b/.gitignore index 71c666d..d9bc5d2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,8 @@ docs-internal/ # Large research data files research/ + + +# Added by cargo + +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..d5ed719 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1675 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "assert_cmd" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c5bcfa8749ac45dd12cb11055aeeb6b27a3895560d60d71e3c23bf979e60514" +dependencies = [ + "anstyle", + "bstr", + "libc", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bstr" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "regex-automata", + "serde", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "clap" +version = "4.5.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_complete" +version = "4.5.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c757a3b7e39161a4e56f9365141ada2a6c915a8622c408ab6bb4b5d047371031" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "comfy-table" +version = "7.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "958c5d6ecf1f214b4c2bbbbf6ab9523a864bd136dcf71a7e8904799acfe1ad47" +dependencies = [ + "crossterm", + "unicode-segmentation", + "unicode-width", +] + +[[package]] +name = "cookie" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "cookie_store" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b2c103cf610ec6cae3da84a766285b42fd16aad564758459e6ecf128c75206" +dependencies = [ + "cookie", + "document-features", + "idna", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "time", + "url", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossterm" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" +dependencies = [ + "bitflags", + "crossterm_winapi", + "document-features", + "parking_lot", + "rustix", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "directories" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a49173b84e034382284f27f1af4dcbbd231ffa358c0fe316541a7337f376a35" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "float-cmp" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09cf3155332e944990140d967ff5eceb70df778b34f77d8075db46e4704e6d8" +dependencies = [ + "num-traits", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "idx-cli" +version = "0.1.0" +dependencies = [ + "assert_cmd", + "chrono", + "clap", + "clap_complete", + "comfy-table", + "directories", + "owo-colors", + "predicates", + "serde", + "serde_json", + "thiserror 2.0.18", + "toml", + "ureq", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49715b7073f385ba4bc528e5747d02e66cb39c6146efb66b781f131f0fb399c" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "libredox" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a" +dependencies = [ + "libc", +] + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "litrs" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + +[[package]] +name = "num-conv" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "owo-colors" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d211803b9b6b570f68772237e415a029d5a50c65d382910b879fb19d3271f94d" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "predicates" +version = "3.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ada8f2932f28a27ee7b70dd6c1c39ea0675c55a36879ab92f3a715eaa1e63cfe" +dependencies = [ + "anstyle", + "difflib", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cad38746f3166b4031b1a0d39ad9f954dd291e7854fcc0eed52ee41a0b50d144" + +[[package]] +name = "predicates-tree" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0de1b847b39c8131db0467e9df1ff60e6d0562ab8e9a16e568ad0fdb372e2f2" +dependencies = [ + "predicates-core", + "termtree", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror 1.0.69", +] + +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "758025cb5fccfd3bc2fd74708fd4682be41d99e5dff73c377c0646c6012c73a4" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[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.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "termtree" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + +[[package]] +name = "time-macros" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc97a28575b85cfedf2a7e7d3cc64b3e11bd8ac766666318003abbacc7a21fc" +dependencies = [ + "base64", + "cookie_store", + "flate2", + "log", + "percent-encoding", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "ureq-proto", + "url", + "utf-8", + "webpki-roots", +] + +[[package]] +name = "ureq-proto" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d81f9efa9df032be5934a46a068815a10a042b494b6a58cb0a1a97bb5467ed6f" +dependencies = [ + "base64", + "http", + "httparse", + "log", +] + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf-8" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wait-timeout" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6532f9a5c1ece3798cb1c2cfdba640b9b3ba884f5db45973a6f442510a87d38e" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18a2d50fcf105fb33bb15f00e7a77b772945a2ee45dcf454961fd843e74c18e6" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ce4caeaac547cdf713d280eda22a730824dd11e6b8c3ca9e42247b25c631e3" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75a326b8c223ee17883a4251907455a2431acc2791c98c26279376490c378c16" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "webpki-roots" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cfaf3c063993ff62e73cb4311efde4db1efb31ab78a3e5c457939ad5cc0bed" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[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.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +dependencies = [ + "memchr", +] + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..47f5719 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "idx-cli" +version = "0.1.0" +edition = "2024" + +[dependencies] +clap = { version = "4", features = ["derive"] } +clap_complete = "4" +ureq = { version = "3", features = ["json", "cookies"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +comfy-table = "7" +owo-colors = "4" +toml = "0.8" +directories = "5" +chrono = { version = "0.4", features = ["serde"] } +thiserror = "2" + +[dev-dependencies] +assert_cmd = "2" +predicates = "3" diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 0000000..3478a91 --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1,85 @@ +pub mod types; +pub mod yahoo; + +use crate::error::IdxError; +use types::{Interval, Ohlc, Period, Quote}; + +pub trait MarketDataProvider { + fn quote(&self, symbol: &str) -> Result; + fn history( + &self, + symbol: &str, + period: &Period, + interval: &Interval, + ) -> Result, IdxError>; +} + +pub fn resolve_symbol(symbol: &str, exchange: &str) -> String { + let trimmed = symbol.trim().to_uppercase(); + if let Some((base, suffix)) = trimmed.rsplit_once('.') + && !base.is_empty() + && !suffix.is_empty() + { + return trimmed; + } + format!("{trimmed}.{}", exchange.trim().to_uppercase()) +} + +pub fn default_provider() -> Box { + if std::env::var("IDX_USE_MOCK_PROVIDER").is_ok() { + Box::new(MockProvider) + } else { + Box::new(yahoo::YahooProvider::new()) + } +} + +struct MockProvider; + +impl MarketDataProvider for MockProvider { + fn quote(&self, symbol: &str) -> Result { + Ok(Quote { + symbol: symbol.to_string(), + price: 9875.0, + change: 117.0, + change_pct: 1.2, + volume: 12_300_000, + market_cap: Some(1_215_200_000_000_000.0), + week52_high: Some(10_250.0), + week52_low: Some(7_800.0), + week52_position: Some(0.73), + range_signal: Some("upper".to_string()), + prev_close: Some(9_758.0), + avg_volume: Some(10_000_000), + }) + } + + fn history( + &self, + _symbol: &str, + _period: &Period, + _interval: &Interval, + ) -> Result, IdxError> { + Ok(vec![Ohlc { + date: chrono::NaiveDate::from_ymd_opt(2026, 3, 1).expect("valid date"), + open: 9800.0, + high: 9900.0, + low: 9750.0, + close: 9875.0, + volume: 12_300_000, + }]) + } +} + +#[cfg(test)] +mod tests { + use super::resolve_symbol; + + #[test] + fn resolves_symbol_variants() { + assert_eq!(resolve_symbol("bbca", "JK"), "BBCA.JK"); + assert_eq!(resolve_symbol("BBCA.JK", "JK"), "BBCA.JK"); + assert_eq!(resolve_symbol("TLKM.us", "JK"), "TLKM.US"); + assert_eq!(resolve_symbol("abcd.ef.gh", "JK"), "ABCD.EF.GH"); + assert_eq!(resolve_symbol(" bbri ", "jk"), "BBRI.JK"); + } +} diff --git a/src/api/types.rs b/src/api/types.rs new file mode 100644 index 0000000..0dee040 --- /dev/null +++ b/src/api/types.rs @@ -0,0 +1,84 @@ +use chrono::NaiveDate; +use clap::ValueEnum; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Quote { + pub symbol: String, + pub price: f64, + pub change: f64, + pub change_pct: f64, + pub volume: u64, + pub market_cap: Option, + pub week52_high: Option, + pub week52_low: Option, + pub week52_position: Option, + pub range_signal: Option, + pub prev_close: Option, + pub avg_volume: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Ohlc { + pub date: NaiveDate, + pub open: f64, + pub high: f64, + pub low: f64, + pub close: f64, + pub volume: u64, +} + +#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum)] +pub enum Period { + #[value(name = "1d")] + OneDay, + #[value(name = "5d")] + FiveDays, + #[value(name = "1mo")] + OneMonth, + #[value(name = "3mo")] + ThreeMonths, + #[value(name = "6mo")] + SixMonths, + #[value(name = "1y")] + OneYear, + #[value(name = "2y")] + TwoYears, + #[value(name = "5y")] + FiveYears, +} + +impl Period { + pub fn as_str(&self) -> &'static str { + match self { + Self::OneDay => "1d", + Self::FiveDays => "5d", + Self::OneMonth => "1mo", + Self::ThreeMonths => "3mo", + Self::SixMonths => "6mo", + Self::OneYear => "1y", + Self::TwoYears => "2y", + Self::FiveYears => "5y", + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum)] +pub enum Interval { + #[value(name = "1d")] + Day, + #[value(name = "1wk")] + Week, + #[value(name = "1mo")] + Month, +} + +impl Interval { + pub fn as_str(&self) -> &'static str { + match self { + Self::Day => "1d", + Self::Week => "1wk", + Self::Month => "1mo", + } + } +} diff --git a/src/api/yahoo.rs b/src/api/yahoo.rs new file mode 100644 index 0000000..43c202d --- /dev/null +++ b/src/api/yahoo.rs @@ -0,0 +1,259 @@ +use std::time::Duration; + +use serde::Deserialize; + +use crate::api::types::{Interval, Ohlc, Period, Quote}; +use crate::api::MarketDataProvider; +use crate::error::IdxError; + +const USER_AGENT: &str = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"; + +pub struct YahooProvider { + agent: ureq::Agent, +} + +impl YahooProvider { + pub fn new() -> Self { + Self { + agent: ureq::Agent::new_with_defaults(), + } + } + + fn crumb(&self) -> Result { + let resp = self + .agent + .get("https://query1.finance.yahoo.com/v1/test/getcrumb") + .header("User-Agent", USER_AGENT) + .call() + .map_err(|e| IdxError::Http(e.to_string()))?; + + let mut body = resp.into_body(); + body.read_to_string() + .map(|s| s.trim().to_string()) + .map_err(|e| IdxError::Http(e.to_string())) + } + + fn chart_url(symbol: &str, period: &Period, interval: &Interval, crumb: &str) -> String { + format!( + "https://query1.finance.yahoo.com/v8/finance/chart/{symbol}?range={}&interval={}&crumb={crumb}", + period.as_str(), + interval.as_str() + ) + } + + fn fetch_chart(&self, symbol: &str, period: &Period, interval: &Interval) -> Result { + let crumb = self.crumb()?; + let mut wait = Duration::from_millis(250); + for _ in 0..3 { + let url = Self::chart_url(symbol, period, interval, &crumb); + let response = self + .agent + .get(&url) + .header("User-Agent", USER_AGENT) + .call(); + match response { + Ok(ok) => { + return ok + .into_body() + .read_json::() + .map_err(|e| IdxError::ParseError(e.to_string())); + } + Err(ureq::Error::StatusCode(429)) => { + std::thread::sleep(wait + jitter()); + wait *= 2; + } + Err(e) => return Err(IdxError::Http(e.to_string())), + } + } + Err(IdxError::RateLimited) + } +} + +fn jitter() -> Duration { + let millis = (std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.subsec_millis() % 100) + .unwrap_or(42)) as u64; + Duration::from_millis(millis) +} + +impl MarketDataProvider for YahooProvider { + fn quote(&self, symbol: &str) -> Result { + let chart = self.fetch_chart(symbol, &Period::OneDay, &Interval::Day)?; + parse_quote(symbol, &chart) + } + + fn history(&self, symbol: &str, period: &Period, interval: &Interval) -> Result, IdxError> { + let chart = self.fetch_chart(symbol, period, interval)?; + parse_history(&chart) + } +} + +fn parse_quote(symbol: &str, chart: &ChartResponse) -> Result { + let result = chart + .chart + .result + .as_ref() + .and_then(|r| r.first()) + .ok_or(IdxError::ProviderUnavailable)?; + let meta = result.meta.as_ref().ok_or(IdxError::ProviderUnavailable)?; + let price = meta.regular_market_price.ok_or(IdxError::SymbolNotFound(symbol.to_string()))?; + let prev_close = meta.previous_close; + let change = prev_close.map_or(0.0, |p| price - p); + let change_pct = prev_close.map_or(0.0, |p| if p != 0.0 { (change / p) * 100.0 } else { 0.0 }); + + let (week52_position, range_signal) = match (meta.fifty_two_week_low, meta.fifty_two_week_high) { + (Some(low), Some(high)) if high > low => { + let pos = (price - low) / (high - low); + let signal = if pos > 0.66 { + "upper" + } else if pos < 0.33 { + "lower" + } else { + "middle" + }; + (Some(pos), Some(signal.to_string())) + } + _ => (None, None), + }; + + Ok(Quote { + symbol: meta.symbol.clone().unwrap_or_else(|| symbol.to_string()), + price, + change, + change_pct, + volume: meta.regular_market_volume.unwrap_or(0), + market_cap: meta.market_cap, + week52_high: meta.fifty_two_week_high, + week52_low: meta.fifty_two_week_low, + week52_position, + range_signal, + prev_close, + avg_volume: meta.average_daily_volume_3month, + }) +} + +fn parse_history(chart: &ChartResponse) -> Result, IdxError> { + let result = chart + .chart + .result + .as_ref() + .and_then(|r| r.first()) + .ok_or(IdxError::ProviderUnavailable)?; + let timestamps = result.timestamp.as_ref().ok_or(IdxError::ProviderUnavailable)?; + let quote = result + .indicators + .as_ref() + .and_then(|i| i.quote.as_ref()) + .and_then(|q| q.first()) + .ok_or(IdxError::ProviderUnavailable)?; + + let mut out = Vec::new(); + for (i, ts) in timestamps.iter().enumerate() { + let open = quote.open.as_ref().and_then(|v| v.get(i).copied().flatten()); + let high = quote.high.as_ref().and_then(|v| v.get(i).copied().flatten()); + let low = quote.low.as_ref().and_then(|v| v.get(i).copied().flatten()); + let close = quote.close.as_ref().and_then(|v| v.get(i).copied().flatten()); + let volume = quote.volume.as_ref().and_then(|v| v.get(i).copied().flatten()); + + if let (Some(open), Some(high), Some(low), Some(close), Some(volume)) = + (open, high, low, close, volume) + && let Some(dt) = chrono::DateTime::from_timestamp(*ts, 0) + { + out.push(Ohlc { + date: dt.date_naive(), + open, + high, + low, + close, + volume, + }); + } + } + Ok(out) +} + +#[derive(Debug, Deserialize)] +struct ChartResponse { + chart: ChartRoot, +} + +#[derive(Debug, Deserialize)] +struct ChartRoot { + result: Option>, +} + +#[derive(Debug, Deserialize)] +struct ChartResult { + meta: Option, + timestamp: Option>, + indicators: Option, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct ChartMeta { + symbol: Option, + regular_market_price: Option, + previous_close: Option, + regular_market_volume: Option, + market_cap: Option, + fifty_two_week_high: Option, + fifty_two_week_low: Option, + average_daily_volume_3month: Option, +} + +#[derive(Debug, Deserialize)] +struct Indicators { + quote: Option>, +} + +#[derive(Debug, Deserialize)] +struct IndicatorQuote { + open: Option>>, + high: Option>>, + low: Option>>, + close: Option>>, + volume: Option>>, +} + +#[cfg(test)] +mod tests { + use super::{parse_history, parse_quote, ChartResponse}; + + const SAMPLE: &str = r#"{ + "chart": { + "result": [{ + "meta": { + "symbol": "BBCA.JK", + "regularMarketPrice": 9875.0, + "previousClose": 9758.0, + "regularMarketVolume": 12300000, + "marketCap": 1215200000000000, + "fiftyTwoWeekHigh": 10250.0, + "fiftyTwoWeekLow": 7800.0, + "averageDailyVolume3Month": 10000000 + }, + "timestamp": [1709251200,1709337600], + "indicators": {"quote":[{ + "open":[9800.0,9850.0], + "high":[9900.0,9900.0], + "low":[9750.0,9800.0], + "close":[9875.0,9880.0], + "volume":[12300000,11000000] + }]} + }] + } + }"#; + + #[test] + fn parses_quote_and_history() { + let chart: ChartResponse = serde_json::from_str(SAMPLE).expect("valid chart fixture"); + let quote = parse_quote("BBCA.JK", &chart).expect("quote parsed"); + assert_eq!(quote.symbol, "BBCA.JK"); + assert_eq!(quote.price, 9875.0); + let history = parse_history(&chart).expect("history parsed"); + assert_eq!(history.len(), 2); + assert_eq!(history[0].close, 9875.0); + } +} diff --git a/src/cache.rs b/src/cache.rs new file mode 100644 index 0000000..6df817e --- /dev/null +++ b/src/cache.rs @@ -0,0 +1 @@ +// Cache module placeholder for MVP foundation. diff --git a/src/cli/cache.rs b/src/cli/cache.rs new file mode 100644 index 0000000..cadcbd5 --- /dev/null +++ b/src/cli/cache.rs @@ -0,0 +1,13 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Args)] +pub struct CacheCmd { + #[command(subcommand)] + pub command: CacheSubcommand, +} + +#[derive(Debug, Subcommand)] +pub enum CacheSubcommand { + Info, + Clear, +} diff --git a/src/cli/config.rs b/src/cli/config.rs new file mode 100644 index 0000000..13d6c54 --- /dev/null +++ b/src/cli/config.rs @@ -0,0 +1,15 @@ +use clap::{Args, Subcommand}; + +#[derive(Debug, Args)] +pub struct ConfigCmd { + #[command(subcommand)] + pub command: ConfigSubcommand, +} + +#[derive(Debug, Subcommand)] +pub enum ConfigSubcommand { + Init, + Get { key: String }, + Set { key: String, value: String }, + Path, +} diff --git a/src/cli/mod.rs b/src/cli/mod.rs new file mode 100644 index 0000000..239ed06 --- /dev/null +++ b/src/cli/mod.rs @@ -0,0 +1,38 @@ +pub mod cache; +pub mod config; +pub mod stocks; + +use clap::{Parser, Subcommand, ValueEnum}; + +use crate::output::OutputFormat; + +#[derive(Debug, Clone, ValueEnum)] +pub enum Shell { + Bash, + Zsh, + Fish, +} + +#[derive(Debug, Parser)] +#[command(name = "idx", about = "Indonesian stock analysis CLI")] +pub struct Cli { + #[arg(short, long, value_enum, global = true, default_value_t = OutputFormat::Table)] + pub output: OutputFormat, + #[arg(long, global = true)] + pub no_color: bool, + #[arg(short, long, global = true)] + pub quiet: bool, + #[arg(short, long, global = true, action = clap::ArgAction::Count)] + pub verbose: u8, + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Debug, Subcommand)] +pub enum Commands { + Stocks(stocks::StocksCmd), + Config(config::ConfigCmd), + Cache(cache::CacheCmd), + Completions { shell: Shell }, + Version, +} diff --git a/src/cli/stocks.rs b/src/cli/stocks.rs new file mode 100644 index 0000000..0ef2ff3 --- /dev/null +++ b/src/cli/stocks.rs @@ -0,0 +1,51 @@ +use clap::{Args, Subcommand}; + +use crate::api::types::{Interval, Period}; +use crate::api::MarketDataProvider; +use crate::config::IdxConfig; +use crate::error::IdxError; +use crate::output::{render_history, render_quotes}; + +#[derive(Debug, Args)] +pub struct StocksCmd { + #[command(subcommand)] + pub command: StocksSubcommand, +} + +#[derive(Debug, Subcommand)] +pub enum StocksSubcommand { + Quote { symbols: Vec }, + History { + symbol: String, + #[arg(long, value_enum, default_value_t = Period::ThreeMonths)] + period: Period, + #[arg(long, value_enum, default_value_t = Interval::Day)] + interval: Interval, + }, +} + +pub fn handle( + cmd: &StocksCmd, + config: &IdxConfig, + provider: &dyn MarketDataProvider, +) -> Result<(), IdxError> { + match &cmd.command { + StocksSubcommand::Quote { symbols } => { + let mut quotes = Vec::new(); + for sym in symbols.iter().flat_map(|s| s.split(',')) { + let resolved = crate::api::resolve_symbol(sym, &config.exchange); + quotes.push(provider.quote(&resolved)?); + } + render_quotes("es, &config.output, config.no_color) + } + StocksSubcommand::History { + symbol, + period, + interval, + } => { + let resolved = crate::api::resolve_symbol(symbol, &config.exchange); + let history = provider.history(&resolved, period, interval)?; + render_history(&resolved, &history, &config.output) + } + } +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..c926a28 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,121 @@ +use std::fs; +use std::path::PathBuf; + +use directories::ProjectDirs; +use serde::Deserialize; + +use crate::cli::Cli; +use crate::error::IdxError; +use crate::output::OutputFormat; + +#[derive(Debug, Clone)] +pub struct IdxConfig { + pub exchange: String, + pub output: OutputFormat, + pub no_color: bool, + pub quote_ttl: u64, + pub fundamental_ttl: u64, +} + +#[derive(Debug, Deserialize, Default)] +struct FileConfig { + general: Option, + cache: Option, +} + +#[derive(Debug, Deserialize, Default)] +struct FileGeneral { + exchange: Option, + output: Option, + color: Option, +} + +#[derive(Debug, Deserialize, Default)] +struct FileCache { + quote_ttl: Option, + fundamental_ttl: Option, +} + +impl Default for IdxConfig { + fn default() -> Self { + Self { + exchange: "JK".to_string(), + output: OutputFormat::Table, + no_color: false, + quote_ttl: 300, + fundamental_ttl: 3600, + } + } +} + +impl IdxConfig { + pub fn load_with_cli(cli: &Cli) -> Result { + let mut cfg = Self::load()?; + + if let Ok(exchange) = std::env::var("IDX_EXCHANGE") { + cfg.exchange = exchange; + } + if let Ok(output) = std::env::var("IDX_OUTPUT") { + cfg.output = if output.eq_ignore_ascii_case("json") { + OutputFormat::Json + } else { + OutputFormat::Table + }; + } + if let Ok(no_color) = std::env::var("IDX_NO_COLOR") { + cfg.no_color = no_color == "1" || no_color.eq_ignore_ascii_case("true"); + } + + cfg.output = cli.output; + cfg.no_color = cfg.no_color || cli.no_color; + + Ok(cfg) + } + + pub fn load() -> Result { + let mut cfg = Self::default(); + let path = config_path()?; + if path.exists() { + let raw = fs::read_to_string(&path).map_err(|e| IdxError::Io(e.to_string()))?; + let parsed: FileConfig = toml::from_str(&raw).map_err(|e| IdxError::ConfigError(e.to_string()))?; + if let Some(general) = parsed.general { + if let Some(exchange) = general.exchange { + cfg.exchange = exchange; + } + if let Some(output) = general.output { + cfg.output = output; + } + if let Some(color) = general.color { + cfg.no_color = !color; + } + } + if let Some(cache) = parsed.cache { + if let Some(v) = cache.quote_ttl { + cfg.quote_ttl = v; + } + if let Some(v) = cache.fundamental_ttl { + cfg.fundamental_ttl = v; + } + } + } + Ok(cfg) + } +} + +pub fn config_path() -> Result { + ProjectDirs::from("com", "idx", "idx") + .map(|d| d.config_dir().join("config.toml")) + .ok_or_else(|| IdxError::ConfigError("unable to resolve config dir".to_string())) +} + +#[cfg(test)] +mod tests { + use super::IdxConfig; + + #[test] + fn default_values_are_sane() { + let cfg = IdxConfig::default(); + assert_eq!(cfg.exchange, "JK"); + assert_eq!(cfg.quote_ttl, 300); + } +} diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..e372447 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,69 @@ +use serde::Serialize; +use thiserror::Error; + +#[allow(dead_code)] +#[derive(Debug, Error)] +pub enum IdxError { + #[error("symbol not found: {0}")] + SymbolNotFound(String), + #[error("provider rate limited")] + RateLimited, + #[error("provider unavailable")] + ProviderUnavailable, + #[error("parse error: {0}")] + ParseError(String), + #[error("cache miss: {0}")] + CacheMiss(String), + #[error("config error: {0}")] + ConfigError(String), + #[error("io error: {0}")] + Io(String), + #[error("http error: {0}")] + Http(String), +} + +#[derive(Debug, Clone, Copy, Serialize, PartialEq, Eq)] +pub enum ErrorCode { + SymbolNotFound, + RateLimited, + ProviderUnavailable, + ParseError, + CacheMiss, + ConfigError, + Io, + Http, +} + +impl IdxError { + pub fn code(&self) -> ErrorCode { + match self { + Self::SymbolNotFound(_) => ErrorCode::SymbolNotFound, + Self::RateLimited => ErrorCode::RateLimited, + Self::ProviderUnavailable => ErrorCode::ProviderUnavailable, + Self::ParseError(_) => ErrorCode::ParseError, + Self::CacheMiss(_) => ErrorCode::CacheMiss, + Self::ConfigError(_) => ErrorCode::ConfigError, + Self::Io(_) => ErrorCode::Io, + Self::Http(_) => ErrorCode::Http, + } + } + + pub fn exit_code(&self) -> i32 { + 1 + } +} + +#[cfg(test)] +mod tests { + use super::{ErrorCode, IdxError}; + + #[test] + fn display_and_code_work() { + let err = IdxError::SymbolNotFound("BBCA".to_string()); + assert_eq!(err.to_string(), "symbol not found: BBCA"); + assert_eq!(err.code(), ErrorCode::SymbolNotFound); + + let parse = IdxError::ParseError("bad json".to_string()); + assert_eq!(parse.code(), ErrorCode::ParseError); + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..fcbc1da --- /dev/null +++ b/src/main.rs @@ -0,0 +1,54 @@ +mod api; +mod cache; +mod cli; +mod config; +mod error; +mod output; + +use clap::CommandFactory; +use clap::Parser; +use clap_complete::{generate, shells}; + +use crate::api::default_provider; +use crate::cli::{Cli, Commands}; +use crate::config::IdxConfig; +use crate::error::IdxError; +use crate::output::emit_error; + +fn main() { + if let Err(err) = run() { + std::process::exit(err.exit_code()); + } +} + +fn run() -> Result<(), IdxError> { + let cli = Cli::parse(); + let config = IdxConfig::load_with_cli(&cli)?; + + match &cli.command { + Commands::Version => { + println!("{}", env!("CARGO_PKG_VERSION")); + } + Commands::Completions { shell } => { + let mut cmd = Cli::command(); + let name = cmd.get_name().to_owned(); + match shell { + cli::Shell::Bash => generate(shells::Bash, &mut cmd, name, &mut std::io::stdout()), + cli::Shell::Zsh => generate(shells::Zsh, &mut cmd, name, &mut std::io::stdout()), + cli::Shell::Fish => generate(shells::Fish, &mut cmd, name, &mut std::io::stdout()), + } + } + Commands::Stocks(stocks) => { + let provider = default_provider(); + if let Err(err) = cli::stocks::handle(stocks, &config, provider.as_ref()) { + emit_error(&err, &config.output); + return Err(err); + } + } + Commands::Config(_) | Commands::Cache(_) => { + println!("Not implemented yet"); + } + } + + Ok(()) +} diff --git a/src/output/json.rs b/src/output/json.rs new file mode 100644 index 0000000..aa88aa6 --- /dev/null +++ b/src/output/json.rs @@ -0,0 +1,9 @@ +use serde::Serialize; + +use crate::error::IdxError; + +pub fn print_json(value: &T) -> Result<(), IdxError> { + let out = serde_json::to_string_pretty(value).map_err(|e| IdxError::ParseError(e.to_string()))?; + println!("{out}"); + Ok(()) +} diff --git a/src/output/mod.rs b/src/output/mod.rs new file mode 100644 index 0000000..0b0db34 --- /dev/null +++ b/src/output/mod.rs @@ -0,0 +1,44 @@ +pub mod json; +pub mod table; + +use clap::ValueEnum; +use serde::Serialize; + +use crate::api::types::{Ohlc, Quote}; +use crate::error::IdxError; + +#[derive(Debug, Clone, Copy, ValueEnum, PartialEq, Eq, Serialize, serde::Deserialize, Default)] +#[serde(rename_all = "lowercase")] +pub enum OutputFormat { + #[default] + Table, + Json, +} + +pub fn render_quotes(quotes: &[Quote], format: &OutputFormat, no_color: bool) -> Result<(), IdxError> { + match format { + OutputFormat::Table => table::print_quotes(quotes, no_color), + OutputFormat::Json => json::print_json(quotes), + } +} + +pub fn render_history(symbol: &str, history: &[Ohlc], format: &OutputFormat) -> Result<(), IdxError> { + match format { + OutputFormat::Table => table::print_history(symbol, history), + OutputFormat::Json => json::print_json(history), + } +} + +pub fn emit_error(err: &IdxError, format: &OutputFormat) { + match format { + OutputFormat::Table => eprintln!("Error: {err}"), + OutputFormat::Json => { + let payload = serde_json::json!({ + "error": true, + "code": format!("{:?}", err.code()).to_uppercase(), + "message": err.to_string() + }); + eprintln!("{}", serde_json::to_string_pretty(&payload).unwrap_or_else(|_| "{}".to_string())); + } + } +} diff --git a/src/output/table.rs b/src/output/table.rs new file mode 100644 index 0000000..7d61769 --- /dev/null +++ b/src/output/table.rs @@ -0,0 +1,80 @@ +use comfy_table::{presets::UTF8_FULL, Cell, Color, ContentArrangement, Table}; +use owo_colors::OwoColorize; + +use crate::api::types::{Ohlc, Quote}; +use crate::error::IdxError; + +pub fn format_idr(value: f64) -> String { + let rounded = value.round() as i64; + let chars: Vec = rounded.to_string().chars().rev().collect(); + let mut out = String::new(); + for (i, ch) in chars.iter().enumerate() { + if i > 0 && i % 3 == 0 { + out.push(','); + } + out.push(*ch); + } + out.chars().rev().collect() +} + +pub fn print_quotes(quotes: &[Quote], no_color: bool) -> Result<(), IdxError> { + let mut table = Table::new(); + table + .load_preset(UTF8_FULL) + .set_content_arrangement(ContentArrangement::Dynamic) + .set_header(vec!["SYMBOL", "PRICE", "CHG", "CHG%", "VOLUME", "MKT CAP"]); + + for q in quotes { + let pct = format!("{:+.2}%", q.change_pct); + let pct_cell = if no_color { + Cell::new(pct) + } else if q.change_pct >= 0.0 { + Cell::new(pct).fg(Color::Green) + } else { + Cell::new(pct).fg(Color::Red) + }; + table.add_row(vec![ + Cell::new(&q.symbol), + Cell::new(format_idr(q.price)), + Cell::new(format!("{:+.2}", q.change)), + pct_cell, + Cell::new(format_idr(q.volume as f64)), + Cell::new(q.market_cap.map(format_idr).unwrap_or_else(|| "-".to_string())), + ]); + } + + println!("{table}"); + Ok(()) +} + +pub fn print_history(symbol: &str, history: &[Ohlc]) -> Result<(), IdxError> { + println!("{}", format!("History for {symbol}").bold()); + let mut table = Table::new(); + table + .load_preset(UTF8_FULL) + .set_content_arrangement(ContentArrangement::Dynamic) + .set_header(vec!["DATE", "OPEN", "HIGH", "LOW", "CLOSE", "VOLUME"]); + for item in history { + table.add_row(vec![ + Cell::new(item.date), + Cell::new(format_idr(item.open)), + Cell::new(format_idr(item.high)), + Cell::new(format_idr(item.low)), + Cell::new(format_idr(item.close)), + Cell::new(format_idr(item.volume as f64)), + ]); + } + println!("{table}"); + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::format_idr; + + #[test] + fn formats_idr_numbers() { + assert_eq!(format_idr(9875.0), "9,875"); + assert_eq!(format_idr(1_215_200_000_000_000.0), "1,215,200,000,000,000"); + } +} diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..e00b116 --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,54 @@ +use assert_cmd::Command; +use predicates::prelude::*; + +#[test] +fn help_works() { + Command::cargo_bin("idx-cli") + .expect("binary exists") + .arg("--help") + .assert() + .success(); +} + +#[test] +fn version_prints_cargo_version() { + Command::cargo_bin("idx-cli") + .expect("binary exists") + .arg("version") + .assert() + .success() + .stdout(predicate::str::contains(env!("CARGO_PKG_VERSION"))); +} + +#[test] +fn quote_with_mock_provider_json() { + Command::cargo_bin("idx-cli") + .expect("binary exists") + .env("IDX_USE_MOCK_PROVIDER", "1") + .args(["-o", "json", "stocks", "quote", "BBCA,BBRI"]) + .assert() + .success() + .stdout(predicate::str::contains("BBCA.JK")) + .stdout(predicate::str::contains("BBRI.JK")); +} + +#[test] +fn history_with_mock_provider_json() { + Command::cargo_bin("idx-cli") + .expect("binary exists") + .env("IDX_USE_MOCK_PROVIDER", "1") + .args([ + "-o", + "json", + "stocks", + "history", + "BBCA", + "--period", + "3mo", + "--interval", + "1d", + ]) + .assert() + .success() + .stdout(predicate::str::contains("2026-03-01")); +}