wip: migration to clap

This commit is contained in:
Aldo Borrero 2022-12-10 18:25:36 +00:00
parent 897bf115b1
commit 338c997326
10 changed files with 494 additions and 526 deletions

390
Cargo.lock generated
View File

@ -4,27 +4,18 @@ version = 3
[[package]]
name = "aho-corasick"
version = "0.7.18"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
dependencies = [
"winapi",
]
[[package]]
name = "anyhow"
version = "1.0.57"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
[[package]]
name = "atty"
@ -72,18 +63,15 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.9.1"
version = "3.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899"
checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
[[package]]
name = "cast"
version = "0.2.7"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a"
dependencies = [
"rustc_version",
]
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cc"
@ -103,13 +91,59 @@ version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "clap"
version = "4.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d"
dependencies = [
"bitflags",
"clap_derive",
"clap_lex",
"is-terminal",
"once_cell",
"strsim",
"termcolor",
"terminal_size 0.2.3",
"unicase",
"unicode-width",
]
[[package]]
name = "clap-verbosity-flag"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23e2b6c3dcdb73299f48ae05b294da14e2f560b3ed2c09e742269eb1b22af231"
dependencies = [
"clap 4.0.29",
"log",
]
[[package]]
name = "clap_derive"
version = "4.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [
"os_str_bytes",
]
[[package]]
@ -122,7 +156,7 @@ dependencies = [
"lazy_static",
"libc",
"regex",
"terminal_size",
"terminal_size 0.1.17",
"unicode-width",
"winapi",
"winapi-util",
@ -130,22 +164,22 @@ dependencies = [
[[package]]
name = "cpufeatures"
version = "0.2.2"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b"
checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
dependencies = [
"libc",
]
[[package]]
name = "criterion"
version = "0.3.5"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10"
checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f"
dependencies = [
"atty",
"cast",
"clap",
"clap 2.34.0",
"criterion-plot",
"csv",
"itertools",
@ -165,9 +199,9 @@ dependencies = [
[[package]]
name = "criterion-plot"
version = "0.4.4"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57"
checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876"
dependencies = [
"cast",
"itertools",
@ -175,9 +209,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.4"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
dependencies = [
"cfg-if",
"crossbeam-utils",
@ -185,9 +219,9 @@ dependencies = [
[[package]]
name = "crossbeam-deque"
version = "0.8.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
dependencies = [
"cfg-if",
"crossbeam-epoch",
@ -196,26 +230,24 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.8"
version = "0.9.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.8"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
dependencies = [
"cfg-if",
"lazy_static",
]
[[package]]
@ -271,9 +303,9 @@ dependencies = [
[[package]]
name = "either"
version = "1.6.1"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
[[package]]
name = "encode_unicode"
@ -317,23 +349,23 @@ dependencies = [
[[package]]
name = "fastrand"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
dependencies = [
"instant",
]
[[package]]
name = "filetime"
version = "0.2.16"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0408e2626025178a6a7f7ffc05a25bc47103229f19c113755de7bf63816290c"
checksum = "4e884668cd0c7480504233e951174ddc3b382f7c2666e3b7310b5c4e7b0c37f9"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi",
"windows-sys",
]
[[package]]
@ -344,9 +376,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "generic-array"
version = "0.14.5"
version = "0.14.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803"
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
dependencies = [
"typenum",
"version_check",
@ -354,9 +386,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.6"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if",
"libc",
@ -365,9 +397,9 @@ dependencies = [
[[package]]
name = "globset"
version = "0.4.8"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10463d9ff00a2a068db14231982f5132edebad0d7660cd956a1c30292dbcbfbd"
checksum = "0a1e17342619edbc21a964c2afbeb6c820c6a2560032872f397bb97ea127bd0a"
dependencies = [
"aho-corasick",
"bstr",
@ -384,12 +416,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]]
name = "heck"
version = "0.3.3"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
@ -466,9 +495,9 @@ dependencies = [
[[package]]
name = "itertools"
version = "0.10.3"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
dependencies = [
"either",
]
@ -481,15 +510,15 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.1"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
[[package]]
name = "js-sys"
version = "0.3.57"
version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397"
checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
dependencies = [
"wasm-bindgen",
]
@ -514,9 +543,9 @@ checksum = "8f9f08d8963a6c613f4b1a78f4f4a4dbfadf8e6545b2d72861731e4858b8b47f"
[[package]]
name = "log"
version = "0.4.16"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
@ -529,27 +558,27 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memoffset"
version = "0.6.5"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
dependencies = [
"autocfg",
]
[[package]]
name = "num-traits"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.1"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5"
dependencies = [
"hermit-abi 0.1.19",
"libc",
@ -557,9 +586,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.10.0"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
[[package]]
name = "oorandom"
@ -573,6 +602,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "path-clean"
version = "0.1.0"
@ -581,9 +616,9 @@ checksum = "ecba01bf2678719532c5e3059e0b5f0811273d94b397088b82e3bd0a78c78fdd"
[[package]]
name = "plotters"
version = "0.3.1"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a"
checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97"
dependencies = [
"num-traits",
"plotters-backend",
@ -594,15 +629,15 @@ dependencies = [
[[package]]
name = "plotters-backend"
version = "0.3.2"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c"
checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142"
[[package]]
name = "plotters-svg"
version = "0.3.1"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9"
checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f"
dependencies = [
"plotters-backend",
]
@ -633,39 +668,37 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.37"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
"unicode-xid",
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.18"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rayon"
version = "1.5.2"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221"
checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7"
dependencies = [
"autocfg",
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.9.2"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f51245e1e62e1f1629cbfec37b5793bbabcaeb90f30e94d2ba03564687353e4"
checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
@ -675,9 +708,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.2.13"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
@ -695,9 +728,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.5.5"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
dependencies = [
"aho-corasick",
"memchr",
@ -712,9 +745,9 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "regex-syntax"
version = "0.6.25"
version = "0.6.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848"
[[package]]
name = "remove_dir_all"
@ -725,15 +758,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]]
name = "rustix"
version = "0.36.5"
@ -750,9 +774,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.9"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "same-file"
@ -769,17 +793,11 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "semver"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd"
[[package]]
name = "serde"
version = "1.0.137"
version = "1.0.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
checksum = "e326c9ec8042f1b5da33252c8a37e9ffbd2c9bef0155215b6e6c80c790e05f91"
dependencies = [
"serde_derive",
]
@ -796,9 +814,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.137"
version = "1.0.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
checksum = "42a3df25b0713732468deadad63ab9da1f1fd75a48a15024b50363f128db627e"
dependencies = [
"proc-macro2",
"quote",
@ -807,11 +825,11 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.80"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f972498cf015f7c0746cac89ebe1d6ef10c293b94175a243a2d9442c163d9944"
checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
dependencies = [
"itoa 1.0.1",
"itoa 1.0.4",
"ryu",
"serde",
]
@ -831,43 +849,19 @@ dependencies = [
[[package]]
name = "strsim"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "structopt"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.92"
version = "1.0.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52"
checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
"unicode-ident",
]
[[package]]
@ -903,6 +897,16 @@ dependencies = [
"winapi",
]
[[package]]
name = "terminal_size"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907"
dependencies = [
"rustix",
"windows-sys",
]
[[package]]
name = "textwrap"
version = "0.11.0"
@ -914,18 +918,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.31"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.31"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [
"proc-macro2",
"quote",
@ -965,6 +969,8 @@ name = "treefmt"
version = "0.5.0"
dependencies = [
"anyhow",
"clap 4.0.29",
"clap-verbosity-flag",
"console",
"criterion",
"directories",
@ -978,7 +984,6 @@ dependencies = [
"serde",
"serde_json",
"sha-1",
"structopt",
"tempfile",
"toml",
"which",
@ -986,33 +991,30 @@ dependencies = [
[[package]]
name = "typenum"
version = "1.15.0"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "unicode-segmentation"
version = "1.9.0"
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-ident"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
[[package]]
name = "unicode-width"
version = "0.1.9"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "version_check"
@ -1033,15 +1035,15 @@ dependencies = [
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.80"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad"
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@ -1049,13 +1051,13 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.80"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4"
checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
dependencies = [
"bumpalo",
"lazy_static",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
@ -1064,9 +1066,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.80"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5"
checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -1074,9 +1076,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.80"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b"
checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
dependencies = [
"proc-macro2",
"quote",
@ -1087,15 +1089,15 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.80"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744"
checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
[[package]]
name = "web-sys"
version = "0.3.57"
version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283"
checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -1103,13 +1105,13 @@ dependencies = [
[[package]]
name = "which"
version = "4.2.5"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae"
checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b"
dependencies = [
"either",
"lazy_static",
"libc",
"once_cell",
]
[[package]]

View File

@ -32,6 +32,13 @@ panic = "abort"
[dependencies]
anyhow = "1.0"
clap = { version = "4.0.29", features = [
"derive",
"env",
"unicode",
"wrap_help",
] }
clap-verbosity-flag = "2.0.0"
console = "0.13"
directories = "3.0.1"
env_logger = "0.10.0"
@ -44,7 +51,6 @@ rayon = "1.5.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha-1 = "0.9.2"
structopt = "0.3"
tempfile = "3.2.0"
toml = "0.5"
which = "4.0.2"

View File

@ -1 +1 @@
too-many-arguments-threshold = 9
too-many-arguments-threshold = 10

View File

@ -1,66 +0,0 @@
use crate::engine::run_treefmt;
use anyhow::anyhow;
use directories::ProjectDirs;
use log::debug;
use std::path::{Path, PathBuf};
pub fn format_cmd(
tree_root: &Option<PathBuf>,
work_dir: &Path,
config_file: &Path,
paths: &[PathBuf],
no_cache: bool,
clear_cache: bool,
fail_on_change: bool,
allow_missing_formatter: bool,
selected_formatters: &Option<Vec<String>>,
) -> anyhow::Result<()> {
let proj_dirs = match ProjectDirs::from("com", "NumTide", "treefmt") {
Some(x) => x,
None => {
return Err(anyhow!(
"Could not find the project directories. On Unix, check if the HOME env is missing."
))
}
};
// Default the tree root to the folder that contains the config file
let tree_root = tree_root.clone().unwrap_or_else(|| {
// unwrap: since the config_file is a file, there MUST be a parent folder.
config_file.parent().unwrap().to_path_buf()
});
// Default to the tree root if no paths have been given
let paths = if paths.is_empty() {
vec![tree_root.clone()]
} else {
paths.to_owned()
};
let cache_dir = proj_dirs.cache_dir().join("eval-cache");
debug!(
"tree_root={} work_dir={} cache_dir={} config_file={} paths={:?}",
tree_root.display(),
work_dir.display(),
cache_dir.display(),
config_file.display(),
paths
);
// Finally run the main formatter logic from the engine.
run_treefmt(
&tree_root,
work_dir,
&cache_dir,
config_file,
&paths,
no_cache,
clear_cache,
fail_on_change,
allow_missing_formatter,
selected_formatters,
)?;
Ok(())
}

View File

@ -1,78 +0,0 @@
use crate::config;
use crate::engine::run_treefmt_stdin;
use crate::expand_path;
use anyhow::anyhow;
use directories::ProjectDirs;
use log::debug;
use std::path::{Path, PathBuf};
pub fn format_stdin_cmd(
tree_root: &Option<PathBuf>,
work_dir: &Path,
paths: &[PathBuf],
selected_formatters: &Option<Vec<String>>,
) -> anyhow::Result<()> {
let proj_dirs = match ProjectDirs::from("com", "NumTide", "treefmt") {
Some(x) => x,
None => {
return Err(anyhow!(
"Could not find the project directories. On Unix, check if the HOME env is missing."
))
}
};
// Search for the treefmt.toml from there.
let config_file = match config::lookup(work_dir) {
Some(path) => path,
None => {
return Err(anyhow!(
"{} could not be found in {} and up. Use the --init option to create one.",
config::FILENAME,
work_dir.display()
));
}
};
// Default the tree root to the folder that contains the config file
let tree_root = tree_root.clone().unwrap_or_else(|| {
// unwrap: since the config_file is a file, there MUST be a parent folder.
config_file.clone().parent().unwrap().to_path_buf()
});
// Check that only one path was provided
if paths.is_empty() {
return Err(anyhow!(
"--stdin requires the path of the target file as an argument"
));
} else if paths.len() > 1 {
return Err(anyhow!(
"--stdin requires one path but was given {}",
paths.len()
));
}
let path = expand_path(paths.first().unwrap(), work_dir);
let cache_dir = proj_dirs.cache_dir().join("eval-cache");
debug!(
"tree_root={} work_dir={} cache_dir={} config_file={} path={}",
tree_root.display(),
work_dir.display(),
cache_dir.display(),
config_file.display(),
path.display()
);
// Finally run the main formatter logic from the engine.
run_treefmt_stdin(
&tree_root,
work_dir,
&cache_dir,
&config_file,
&path,
selected_formatters,
)?;
Ok(())
}

View File

@ -1,21 +0,0 @@
use crate::config;
use anyhow::Context;
use console::style;
use log::info;
use std::fs;
use std::path::Path;
pub fn init_cmd(work_dir: &Path) -> anyhow::Result<()> {
let file_path = work_dir.join(config::FILENAME);
// TODO: detect if file exists
fs::write(&file_path, std::include_bytes!("init_treefmt.toml")).with_context(|| {
format!(
"{} `{}`",
style("Error writing").bold().red(),
style(file_path.display()).bold()
)
})?;
info!("Generated treefmt template at {}", file_path.display());
Ok(())
}

View File

@ -1,146 +0,0 @@
//! CLI command structures for formatter
#![allow(clippy::redundant_closure)]
mod format;
mod format_stdin;
mod init;
use self::format::format_cmd;
use self::format_stdin::format_stdin_cmd;
use self::init::init_cmd;
use crate::config;
use crate::expand_path;
use anyhow::anyhow;
use std::path::PathBuf;
use structopt::StructOpt;
/// ✨ format all your language!
#[derive(Debug, StructOpt)]
pub struct Cli {
/// Create a new treefmt.toml
#[structopt(long = "init")]
pub init: bool,
/// Format the content passed in stdin
#[structopt(long = "stdin", conflicts_with("init"))]
pub stdin: bool,
/// Ignore the evaluation cache entirely. Useful for CI.
#[structopt(long = "no-cache", conflicts_with("stdin"), conflicts_with("init"))]
pub no_cache: bool,
/// Reset the evaluation cache. Use in case the cache is not precise enough.
#[structopt(long = "clear-cache", conflicts_with("stdin"), conflicts_with("init"))]
pub clear_cache: bool,
/// Exit with error if any changes were made. Useful for CI.
#[structopt(
long = "fail-on-change",
conflicts_with("stdin"),
conflicts_with("init")
)]
pub fail_on_change: bool,
/// Do not exit with error if a configured formatter is missing
#[structopt(long = "allow-missing-formatter")]
pub allow_missing_formatter: bool,
/// Log verbosity is based off the number of v used
#[structopt(long = "verbose", short = "v", parse(from_occurrences))]
pub verbosity: u8,
#[structopt(long = "quiet", short = "q")]
/// No output printed to stderr
pub quiet: bool,
#[structopt(short = "C", default_value = ".")]
/// Run as if treefmt was started in <work-dir> instead of the current working directory.
pub work_dir: PathBuf,
#[structopt(long = "tree-root", env = "PRJ_ROOT")]
/// Set the path to the tree root directory. Defaults to the folder holding the treefmt.toml file.
pub tree_root: Option<PathBuf>,
#[structopt(long = "config-file")]
/// Run with the specified config file, which is not required to be in the tree to be formatted.
pub config_file: Option<PathBuf>,
#[structopt()]
/// Paths to format. Defaults to formatting the whole tree.
pub paths: Vec<PathBuf>,
#[structopt(long = "formatters", short = "f")]
/// Select formatters name to apply. Defaults to all formatters.
pub formatters: Option<Vec<String>>,
}
/// Use this instead of Cli::from_args(). We do a little bit of post-processing here.
pub fn cli_from_args() -> anyhow::Result<Cli> {
let mut cli = Cli::from_args();
let cwd = std::env::current_dir()?;
assert!(cwd.is_absolute());
// Make sure the work_dir is an absolute path. Don't use the stdlib canonicalize() function
// because symlinks should not be resolved.
cli.work_dir = expand_path(&cli.work_dir, &cwd);
// Make sure the tree_root is an absolute path.
if let Some(tree_root) = cli.tree_root {
cli.tree_root = Some(expand_path(&tree_root, &cwd));
}
match cli.config_file {
None => {
// Find the config file if not specified by the user.
cli.config_file = config::lookup(&cli.work_dir);
}
Some(_) => {
if cli.tree_root.is_none() {
return Err(anyhow!(
"If --config-file is set, --tree-root must also be set"
));
}
}
}
// Make sure the config_file points to an absolute path.
if let Some(config_file) = cli.config_file {
cli.config_file = Some(expand_path(&config_file, &cwd));
}
Ok(cli)
}
/// Run a command with the given logger
pub fn run_cli(cli: &Cli) -> anyhow::Result<()> {
if cli.init {
init_cmd(&cli.work_dir)?
} else if cli.stdin {
format_stdin_cmd(&cli.tree_root, &cli.work_dir, &cli.paths, &cli.formatters)?
} else {
// Fail if configuration could not be found. This is checked
// here to avoid aborting before init_cmd.
if cli.config_file.is_none() {
return Err(anyhow!(
"{} could not be found in {} and up. Use the --init option to create one or specify --config-file if it is in a non-standard location.",
config::FILENAME,
cli.work_dir.display(),
));
}
format_cmd(
&cli.tree_root,
&cli.work_dir,
cli.config_file
.as_ref()
.expect("presence asserted in ::cli_from_args"),
&cli.paths,
cli.no_cache,
cli.clear_cache,
cli.fail_on_change,
cli.allow_missing_formatter,
&cli.formatters,
)?
}
Ok(())
}

View File

@ -1,7 +1,5 @@
//! Your favorite all-in-one formatter tool!
#![deny(missing_docs)]
pub mod command;
pub mod config;
pub mod engine;
pub mod eval_cache;

View File

@ -1,31 +1,304 @@
#![allow(clippy::redundant_closure, clippy::redundant_pattern_matching)]
use anyhow::{anyhow, Context};
use clap::Parser;
use clap_verbosity_flag::Verbosity;
use directories::ProjectDirs;
use log::{debug, error, info};
use std::{
env, fs, include_bytes,
path::{Path, PathBuf},
process::ExitCode,
};
use log::{error, LevelFilter};
use treefmt::command::{cli_from_args, run_cli};
use treefmt::{config, engine, expand_path};
fn main() {
if let Err(e) = run() {
error!("{}", e);
::std::process::exit(1);
}
/// Command line options for treefmt.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Create a new treefmt.toml
#[arg(short, long, default_value_t = false)]
init: bool,
/// Format the content passed in stdin.
#[arg(long, default_value_t = false, conflicts_with("init"))]
stdin: bool,
/// Ignore the evaluation cache entirely. Useful for CI.
#[arg(long, conflicts_with("stdin"), conflicts_with("init"))]
no_cache: bool,
/// Reset the evaluation cache. Use in case the cache is not precise enough.
#[arg(short, long, default_value_t = false)]
clear_cache: bool,
/// Exit with error if any changes were made. Useful for CI.
#[arg(
long,
default_value_t = false,
conflicts_with("stdin"),
conflicts_with("init")
)]
fail_on_change: bool,
/// Do not exit with error if a configured formatter is missing.
#[arg(long, default_value_t = false)]
allow_missing_formatter: bool,
#[clap(flatten)]
verbose: Verbosity,
/// Run as if treefmt was started in <work-dir> instead of the current working directory.
#[arg(short, default_value = ".")]
work_dir: PathBuf,
/// Set the path to the tree root directory. Defaults to the folder holding the treefmt.toml file.
#[arg(long, env = "PRJ_ROOT", default_value = ".")]
tree_root: Option<PathBuf>,
/// Run with the specified config file, which is not required to be in the tree to be formatted.
#[arg(long)]
config_file: Option<PathBuf>,
/// Paths to format. Defaults to formatting the whole tree.
#[arg()]
paths: Vec<PathBuf>,
/// Select formatters name to apply. Defaults to all formatters.
#[arg(short, long)]
formatters: Option<Vec<String>>,
}
fn run() -> anyhow::Result<()> {
let cli = cli_from_args()?;
fn main() -> ExitCode {
// TODO: Avoid using this unwrap by migrating this logic to clap
let args = ensure_args_defaults(Cli::parse()).unwrap();
// Configure the logger
env_logger::builder()
.format_timestamp(None)
.format_target(false)
.filter_level(match cli.verbosity {
0 => LevelFilter::Off,
1 => LevelFilter::Info,
2 => LevelFilter::Debug,
_ => LevelFilter::Trace,
})
.filter_level(args.verbose.log_level_filter())
.init();
run_cli(&cli)?;
// Run the app!
match run_arg_command(args) {
Ok(()) => ExitCode::SUCCESS,
Err(e) => {
error!("{}", e);
ExitCode::FAILURE
}
}
}
// TODO: Move this to clap rs parser logic
fn ensure_args_defaults(mut args: Cli) -> anyhow::Result<Cli> {
// Obtain current dir and ensure is absolute
let cwd = env::current_dir()?;
assert!(cwd.is_absolute());
// Make sure the work_dir is an absolute path. Don't use the stdlib canonicalize() function
// because symlinks should not be resolved.
args.work_dir = expand_path(&args.work_dir, &cwd);
// Make sure the tree_root is an absolute path.
if let Some(tree_root) = args.tree_root {
args.tree_root = Some(expand_path(&tree_root, &cwd));
}
match args.config_file {
None => {
// Find the config file if not specified by the user.
args.config_file = config::lookup(&args.work_dir);
}
Some(_) => {
if args.tree_root.is_none() {
return Err(anyhow!(
"If --config-file is set, --tree-root must also be set"
));
}
}
}
// Make sure the config_file points to an absolute path.
if let Some(config_file) = args.config_file {
args.config_file = Some(expand_path(&config_file, &cwd));
}
Ok(args)
}
fn run_arg_command(args: Cli) -> anyhow::Result<()> {
if args.init {
init_cmd(&args.work_dir)?
} else if args.stdin {
format_stdin_cmd(
&args.tree_root,
&args.work_dir,
&args.paths,
&args.formatters,
)?
} else {
// Fail if configuration could not be found. This is checked
// here to avoid aborting before init_cmd.
if args.config_file.is_none() {
return Err(anyhow!(
"{} could not be found in {} and up. Use the --init option to create one or specify --config-file if it is in a non-standard location.",
treefmt::config::FILENAME,
args.work_dir.display(),
));
}
format_cmd(
&args.tree_root,
&args.work_dir,
args.config_file
.as_ref()
.expect("presence asserted in ::cli_from_args"),
&args.paths,
args.no_cache,
args.clear_cache,
args.fail_on_change,
args.allow_missing_formatter,
&args.formatters,
)?
}
Ok(())
}
/// Creates a new treefmt.toml file as a template
fn init_cmd(work_dir: &Path) -> anyhow::Result<()> {
let file_path = work_dir.join(config::FILENAME);
// TODO: detect if file exists
fs::write(&file_path, include_bytes!("init_treefmt.toml")).with_context(|| {
format!(
"{} `{}`",
console::style("Error writing").bold().red(),
console::style(file_path.display()).bold()
)
})?;
info!("Generated treefmt template at {}", file_path.display());
Ok(())
}
/// Performs the formatting of the tree
fn format_cmd(
tree_root: &Option<PathBuf>,
work_dir: &Path,
config_file: &Path,
paths: &[PathBuf],
no_cache: bool,
clear_cache: bool,
fail_on_change: bool,
allow_missing_formatter: bool,
selected_formatters: &Option<Vec<String>>,
) -> anyhow::Result<()> {
let proj_dirs = match ProjectDirs::from("com", "NumTide", "treefmt") {
Some(x) => x,
None => {
return Err(anyhow!(
"Could not find the project directories. On Unix, check if the HOME env is missing."
))
}
};
// Default the tree root to the folder that contains the config file
let tree_root = tree_root.clone().unwrap_or_else(|| {
// unwrap: since the config_file is a file, there MUST be a parent folder.
config_file.parent().unwrap().to_path_buf()
});
// Default to the tree root if no paths have been given
let paths = if paths.is_empty() {
vec![tree_root.clone()]
} else {
paths.to_owned()
};
let cache_dir = proj_dirs.cache_dir().join("eval-cache");
debug!(
"tree_root={} work_dir={} cache_dir={} config_file={} paths={:?}",
tree_root.display(),
work_dir.display(),
cache_dir.display(),
config_file.display(),
paths
);
// Finally run the main formatter logic from the engine.
engine::run_treefmt(
&tree_root,
work_dir,
&cache_dir,
config_file,
&paths,
no_cache,
clear_cache,
fail_on_change,
allow_missing_formatter,
selected_formatters,
)?;
Ok(())
}
/// Performs the formatting of the stdin
fn format_stdin_cmd(
tree_root: &Option<PathBuf>,
work_dir: &Path,
paths: &[PathBuf],
selected_formatters: &Option<Vec<String>>,
) -> anyhow::Result<()> {
let proj_dirs = match ProjectDirs::from("com", "NumTide", "treefmt") {
Some(x) => x,
None => {
return Err(anyhow!(
"Could not find the project directories. On Unix, check if the HOME env is missing."
))
}
};
// Search for the treefmt.toml from there.
let config_file = match config::lookup(work_dir) {
Some(path) => path,
None => {
return Err(anyhow!(
"{} could not be found in {} and up. Use the --init option to create one.",
config::FILENAME,
work_dir.display()
));
}
};
// Default the tree root to the folder that contains the config file
let tree_root = tree_root.clone().unwrap_or_else(|| {
// unwrap: since the config_file is a file, there MUST be a parent folder.
config_file.clone().parent().unwrap().to_path_buf()
});
let path = treefmt::expand_path(paths.first().unwrap(), work_dir);
let cache_dir = proj_dirs.cache_dir().join("eval-cache");
debug!(
"tree_root={} work_dir={} cache_dir={} config_file={} path={}",
tree_root.display(),
work_dir.display(),
cache_dir.display(),
config_file.display(),
path.display()
);
// Finally run the main formatter logic from the engine.
engine::run_treefmt_stdin(
&tree_root,
work_dir,
&cache_dir,
&config_file,
&path,
selected_formatters,
)?;
Ok(())
}