From 3b961906c4497692be65ff31ff26948ff3b85206 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 30 Jan 2021 13:17:37 +0300 Subject: [PATCH 1/6] =?UTF-8?q?chore(deps):=20Run=20=E2=80=98cargo=20updat?= =?UTF-8?q?e=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 95 ++++++++++++++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e974968e..54e37cff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,12 +61,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "byteorder" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" - [[package]] name = "casile" version = "0.4.0" @@ -189,7 +183,7 @@ dependencies = [ "lazy_static", "nom", "rust-ini", - "serde 1.0.119", + "serde 1.0.123", "serde-hjson", "serde_json", "toml", @@ -344,20 +338,11 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "git2" -version = "0.13.15" +version = "0.13.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44f267c9da8a4de3c615b59e23606c75f164f84896e97f4dd6c15a4294de4359" +checksum = "1d250f5f82326884bd39c2853577e70a121775db76818ffa452ed1e80de12986" dependencies = [ "bitflags", "libc", @@ -415,9 +400,9 @@ dependencies = [ [[package]] name = "intl-memoizer" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0ed58ba6089d49f8a9a7d5e16fc9b9e2019cdf40ef270f3d465fa244d9630b" +checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f" dependencies = [ "type-map", "unic-langid", @@ -478,15 +463,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.82" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929" +checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff" [[package]] name = "libgit2-sys" -version = "0.12.17+1.1.0" +version = "0.12.18+1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4ebdf65ca745126df8824688637aa0535a88900b83362d8ca63893bcf4e8841" +checksum = "3da6a42da88fc37ee1ecda212ffa254c25713532980005d5f7c0b0fbe7e6e885" dependencies = [ "cc", "libc", @@ -540,11 +525,11 @@ checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" [[package]] name = "log" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", ] [[package]] @@ -623,6 +608,12 @@ dependencies = [ "libc", ] +[[package]] +name = "once_cell" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" + [[package]] name = "openssl-probe" version = "0.1.2" @@ -662,9 +653,9 @@ checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" [[package]] name = "predicates" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73dd9b7b200044694dfede9edf907c1ca19630908443e9447e624993700c6932" +checksum = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa" dependencies = [ "difference", "float-cmp", @@ -675,15 +666,15 @@ dependencies = [ [[package]] name = "predicates-core" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb3dbeaaf793584e29c58c7e3a82bbb3c7c06b63cea68d13b0e3cddc124104dc" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" [[package]] name = "predicates-tree" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aee95d988ee893cb35c06b148c80ed2cd52c8eea927f50ba7a0be1a786aeab73" +checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" dependencies = [ "predicates-core", "treeline", @@ -844,6 +835,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "ryu" version = "1.0.5" @@ -873,9 +870,9 @@ checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" [[package]] name = "serde" -version = "1.0.119" +version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bdd36f49e35b61d49efd8aa7fc068fd295961fd2286d0b2ee9a4c7a14e99cc3" +checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" [[package]] name = "serde-hjson" @@ -898,7 +895,7 @@ checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" dependencies = [ "itoa", "ryu", - "serde 1.0.119", + "serde 1.0.123", ] [[package]] @@ -946,9 +943,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.58" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" +checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" dependencies = [ "proc-macro2", "quote", @@ -966,9 +963,9 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bd2d183bd3fac5f5fe38ddbeb4dc9aec4a39a9d7d59e7491d900302da01cbe1" +checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" dependencies = [ "libc", "winapi", @@ -986,11 +983,11 @@ dependencies = [ [[package]] name = "thread_local" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" +checksum = "d8208a331e1cb318dd5bd76951d2b8fc48ca38a69f5f4e4af1b6a9f8c6236915" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] @@ -1012,9 +1009,9 @@ checksum = "29738eedb4388d9ea620eeab9384884fc3f06f586a2eddb56bedc5885126c7c1" [[package]] name = "tinyvec" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -1031,7 +1028,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ - "serde 1.0.119", + "serde 1.0.123", ] [[package]] @@ -1042,11 +1039,11 @@ checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] name = "type-map" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d2741b1474c327d95c1f1e3b0a2c3977c8e128409c572a33af2914e7d636717" +checksum = "b6d3364c5e96cb2ad1603037ab253ddd34d7fb72a58bdddf4b7350760fc69a46" dependencies = [ - "fxhash", + "rustc-hash", ] [[package]] From 71e55e0225b6e595739744df434f00a6bf7fb62f Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 30 Jan 2021 13:15:58 +0300 Subject: [PATCH 2/6] chore(deps): Add YAML support to config manager Turns out the feature is enabled by default, but so is a lot of stuff we now know we don't need. Lets lighten the load. --- Cargo.lock | 93 +++--------------------------------------------------- Cargo.toml | 6 +++- 2 files changed, 10 insertions(+), 89 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54e37cff..02bd90bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,7 +116,7 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" dependencies = [ "libc", "num-integer", - "num-traits 0.2.14", + "num-traits", "time", "winapi", ] @@ -182,11 +182,7 @@ checksum = "19b076e143e1d9538dde65da30f8481c2a6c44040edb8e02b9bf1351edb92ce3" dependencies = [ "lazy_static", "nom", - "rust-ini", - "serde 1.0.123", - "serde-hjson", - "serde_json", - "toml", + "serde", "yaml-rust", ] @@ -275,7 +271,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" dependencies = [ - "num-traits 0.2.14", + "num-traits", ] [[package]] @@ -427,12 +423,6 @@ dependencies = [ "either", ] -[[package]] -name = "itoa" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" - [[package]] name = "jobserver" version = "0.1.21" @@ -507,16 +497,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked-hash-map" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd" -dependencies = [ - "serde 0.8.23", - "serde_test", -] - [[package]] name = "linked-hash-map" version = "0.5.4" @@ -577,16 +557,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" dependencies = [ "autocfg", - "num-traits 0.2.14", -] - -[[package]] -name = "num-traits" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" -dependencies = [ - "num-traits 0.2.14", + "num-traits", ] [[package]] @@ -829,12 +800,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "rust-ini" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" - [[package]] name = "rustc-hash" version = "1.1.0" @@ -862,51 +827,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "serde" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" - [[package]] name = "serde" version = "1.0.123" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" -[[package]] -name = "serde-hjson" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8" -dependencies = [ - "lazy_static", - "linked-hash-map 0.3.0", - "num-traits 0.1.43", - "regex", - "serde 0.8.23", -] - -[[package]] -name = "serde_json" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" -dependencies = [ - "itoa", - "ryu", - "serde 1.0.123", -] - -[[package]] -name = "serde_test" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "110b3dbdf8607ec493c22d5d947753282f3bae73c0f56d322af1e8c78e4c23d5" -dependencies = [ - "serde 0.8.23", -] - [[package]] name = "smallvec" version = "1.6.1" @@ -1022,15 +948,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" -[[package]] -name = "toml" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" -dependencies = [ - "serde 1.0.123", -] - [[package]] name = "treeline" version = "0.1.0" @@ -1203,5 +1120,5 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" dependencies = [ - "linked-hash-map 0.5.4", + "linked-hash-map", ] diff --git a/Cargo.toml b/Cargo.toml index 87d83d72..24ed100f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ build = "build.rs" [dependencies] colored = "2.0.0" -config = "0.10.1" fluent = "0.12.0" fluent-fallback = "0.0.4" fluent-langneg = "0.13.0" @@ -26,6 +25,11 @@ rust-embed = "5.7.0" subprocess = "0.2.6" unic-langid = "0.9.0" + [dependencies.config] + version = "0.10.1" + default-features = false + features = [ "yaml" ] + [dependencies.clap] version = "3.0.0-beta.2" features = [ "wrap_help" ] From 282ed8e7aebfcccc8170e195c4e5c391598895ae Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 30 Jan 2021 13:39:35 +0300 Subject: [PATCH 3/6] chore(deps): Lighten the load by removing unused features --- Cargo.lock | 76 ++++++++++++++++++++++-------------------------------- Cargo.toml | 15 ++++++++--- 2 files changed, 43 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02bd90bf..ecf11367 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,10 +5,6 @@ name = "Inflector" version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -dependencies = [ - "lazy_static", - "regex", -] [[package]] name = "aho-corasick" @@ -27,10 +23,11 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "assert_cmd" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dc1679af9a1ab4bea16f228b05d18f8363f8327b1fa8db00d2760cfafc6b61e" +checksum = "f2475b58cd94eb4f70159f4fd8844ba3b807532fe3131b3373fae060bbe30396" dependencies = [ + "bstr", "doc-comment", "predicates", "predicates-core", @@ -61,6 +58,23 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bstr" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", +] + +[[package]] +name = "byteorder" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b" + [[package]] name = "casile" version = "0.4.0" @@ -344,8 +358,6 @@ dependencies = [ "libc", "libgit2-sys", "log", - "openssl-probe", - "openssl-sys", "url", ] @@ -453,36 +465,20 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.84" +version = "0.2.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff" +checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3" [[package]] name = "libgit2-sys" version = "0.12.18+1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3da6a42da88fc37ee1ecda212ffa254c25713532980005d5f7c0b0fbe7e6e885" -dependencies = [ - "cc", - "libc", - "libssh2-sys", - "libz-sys", - "openssl-sys", - "pkg-config", -] - -[[package]] -name = "libssh2-sys" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df40b13fe7ea1be9b9dffa365a51273816c345fc1811478b57ed7d964fbfc4ce" dependencies = [ "cc", "libc", "libz-sys", - "openssl-sys", "pkg-config", - "vcpkg", ] [[package]] @@ -585,25 +581,6 @@ version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" -[[package]] -name = "openssl-probe" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" - -[[package]] -name = "openssl-sys" -version = "0.9.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "os_str_bytes" version = "2.4.0" @@ -730,6 +707,15 @@ dependencies = [ "thread_local", ] +[[package]] +name = "regex-automata" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +dependencies = [ + "byteorder", +] + [[package]] name = "regex-syntax" version = "0.6.22" diff --git a/Cargo.toml b/Cargo.toml index 24ed100f..e857e4d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,13 +14,10 @@ colored = "2.0.0" fluent = "0.12.0" fluent-fallback = "0.0.4" fluent-langneg = "0.13.0" -git2 = "0.13.12" itertools = "0.10.0" -Inflector = "0.11.4" lazy_static = "1.4.0" num_cpus = "1.13.0" rayon = "1.5.0" -regex = "1.4.2" rust-embed = "5.7.0" subprocess = "0.2.6" unic-langid = "0.9.0" @@ -34,6 +31,18 @@ unic-langid = "0.9.0" version = "3.0.0-beta.2" features = [ "wrap_help" ] + [dependencies.git2] + version = "0.13.12" + default-features = false + + [dependencies.Inflector] + version = "0.11.4" + default-features = false + + [dependencies.regex] + version = "1.4.2" + default-features = false + [build-dependencies] clap = "3.0.0-beta.2" clap_generate = "3.0.0-beta.2" From 55f0b6b0a4b175538ed1f7d9dca6ea8426d75eac Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 30 Jan 2021 18:25:54 +0300 Subject: [PATCH 4/6] feat(cli): Merge config values from casile.yml --- src/cli.rs | 2 +- src/config.rs | 33 ++++++++++++++++++++++++--------- src/main.rs | 5 +++-- src/status/mod.rs | 15 +++++++++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 3aafccd0..b087e990 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -15,7 +15,7 @@ pub struct Cli { // FTL: help-flags-language /// Set language - #[clap(short, long, env = "LANG")] + #[clap(short, long)] pub language: Option, // FTL: help-flags-path diff --git a/src/config.rs b/src/config.rs index c0901e93..4e203411 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,9 @@ use crate::cli::Cli; +use crate::status; use crate::Result; -use config::{Config, Environment}; -use std::sync; +use config::{Config, Environment, File, FileFormat}; +use std::{env, sync}; static ERROR_CONFIG_WRITE: &str = "Unable to gain write lock on global app config"; static ERROR_CONFIG_READ: &str = "Unable to gain read lock on global app config"; @@ -13,8 +14,8 @@ lazy_static! { impl CONF { pub fn defaults(&self) -> Result<()> { - self.write() - .expect(ERROR_CONFIG_WRITE) + let mut config = self.write().expect(ERROR_CONFIG_WRITE); + config .set_default("debug", false)? .set_default("quiet", false)? .set_default("verbose", false)? @@ -23,14 +24,28 @@ impl CONF { Ok(()) } - pub fn from_env(&self) -> Result<()> { - self.write() - .expect(ERROR_CONFIG_WRITE) - .merge(Environment::with_prefix("casile"))?; + pub fn merge_env(&self) -> Result<()> { + let mut config = self.write().expect(ERROR_CONFIG_WRITE); + config.merge(Environment::with_prefix("casile"))?; + if let Some(lang) = env::var_os("LANG") { + if lang.len() > 0 { + config.set("language", lang.to_str()); + } + } + Ok(()) + } + + pub fn merge_files(&self) -> Result<()> { + let confs = status::get_confs()?; + let mut config = self.write().expect(ERROR_CONFIG_WRITE); + for (_, conf) in confs.iter().enumerate() { + let f = File::new(conf.to_str().unwrap(), FileFormat::Yaml); + config.merge(f).unwrap(); + } Ok(()) } - pub fn from_args(&self, args: &Cli) -> Result<()> { + pub fn merge_args(&self, args: &Cli) -> Result<()> { if args.debug { self.set_bool("debug", true)?; self.set_bool("verbose", true)?; diff --git a/src/main.rs b/src/main.rs index 6f4b69d5..565d4585 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,8 @@ use std::env; fn main() -> Result<()> { CONF.defaults()?; - CONF.from_env()?; + CONF.merge_env()?; + CONF.merge_files()?; // Workaround for Github Actions usage to make the prebuilt Docker image // invocation interchangeable with the default run-time built invocation we // need to set some default arguments. These are not used by the regular CLI. @@ -24,7 +25,7 @@ fn main() -> Result<()> { let app = Cli::into_app().version(VERSION); let matches = app.get_matches(); let args = Cli::from_arg_matches(&matches); - CONF.from_args(&args)?; + CONF.merge_args(&args)?; casile::show_welcome(); match args.subcommand { Subcommand::Make { target } => make::run(target), diff --git a/src/status/mod.rs b/src/status/mod.rs index b8eaef4e..ecb02f57 100644 --- a/src/status/mod.rs +++ b/src/status/mod.rs @@ -91,6 +91,21 @@ pub fn get_rules() -> Result> { Ok(rules) } +/// Scan for CaSILE configuration files +pub fn get_confs() -> Result> { + let repo = get_repo()?; + let root = repo.workdir().unwrap(); + let files = vec!["casile.yml"]; + let mut confs = Vec::new(); + for file in &files { + let p = root.join(file); + if p.exists() { + confs.push(p); + } + } + Ok(confs) +} + /// Figure out version string from repo tags pub fn get_git_version() -> String { let zero_version = String::from("0.000"); From badb8d795f08c3d0b820cb7555ffd3a43f30bff5 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 3 Feb 2021 12:52:36 +0300 Subject: [PATCH 5/6] chore(cli): Work around config priority issues with language --- src/config.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 4e203411..3e73f9f3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -26,12 +26,14 @@ impl CONF { pub fn merge_env(&self) -> Result<()> { let mut config = self.write().expect(ERROR_CONFIG_WRITE); - config.merge(Environment::with_prefix("casile"))?; if let Some(lang) = env::var_os("LANG") { if lang.len() > 0 { - config.set("language", lang.to_str()); + if let None = env::var_os("CASILE_LANGUAGELANG") { + env::set_var("CASILE_LANGUAGE", lang); + } } } + config.merge(Environment::with_prefix("casile"))?; Ok(()) } From e75112569026ff83e4676618e5012a7504a1aca1 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Thu, 4 Feb 2021 12:10:24 +0300 Subject: [PATCH 6/6] fix(cli): Allow --version to work outside of a repo --- src/status/mod.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/status/mod.rs b/src/status/mod.rs index ecb02f57..fa793625 100644 --- a/src/status/mod.rs +++ b/src/status/mod.rs @@ -93,14 +93,15 @@ pub fn get_rules() -> Result> { /// Scan for CaSILE configuration files pub fn get_confs() -> Result> { - let repo = get_repo()?; - let root = repo.workdir().unwrap(); let files = vec!["casile.yml"]; let mut confs = Vec::new(); - for file in &files { - let p = root.join(file); - if p.exists() { - confs.push(p); + if let Ok(repo) = get_repo() { + let root = repo.workdir().unwrap(); + for file in &files { + let p = root.join(file); + if p.exists() { + confs.push(p); + } } } Ok(confs)