Use workspace for xtask
This commit is contained in:
parent
917663485f
commit
ead4b4b004
|
|
@ -1,2 +1,2 @@
|
||||||
[alias]
|
[alias]
|
||||||
xtask = "run --manifest-path ./xtask/Cargo.toml --"
|
xtask = "run --package xtask --"
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@ version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "anyhow"
|
name = "anyhow"
|
||||||
version = "1.0.43"
|
version = "1.0.44"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf"
|
checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayvec"
|
name = "arrayvec"
|
||||||
|
|
@ -57,9 +57,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "assert_cmd"
|
name = "assert_cmd"
|
||||||
version = "2.0.1"
|
version = "2.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b800c4403e8105d959595e1f88119e78bc12bc874c4336973658b648a746ba93"
|
checksum = "e996dc7940838b7ef1096b882e29ec30a3149a3a443cdc8dba19ed382eca1fe2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bstr",
|
"bstr",
|
||||||
"doc-comment",
|
"doc-comment",
|
||||||
|
|
@ -115,9 +115,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bstr"
|
name = "bstr"
|
||||||
version = "0.2.16"
|
version = "0.2.17"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279"
|
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
@ -302,9 +302,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.101"
|
version = "0.2.103"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
|
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
|
|
@ -357,9 +357,9 @@ checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates"
|
name = "predicates"
|
||||||
version = "2.0.2"
|
version = "2.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c143348f141cc87aab5b950021bac6145d0e5ae754b0591de23244cee42c9308"
|
checksum = "5c6ce811d0b2e103743eec01db1c50612221f173084ce2f7941053e94b6bb474"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"difflib",
|
"difflib",
|
||||||
"itertools",
|
"itertools",
|
||||||
|
|
@ -374,12 +374,12 @@ checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "predicates-tree"
|
name = "predicates-tree"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d7dd0fd014130206c9352efbdc92be592751b2b9274dff685348341082c6ea3d"
|
checksum = "338c7be2905b732ae3984a2f40032b5e94fd8f52505b186c7d4d68d193445df7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"predicates-core",
|
"predicates-core",
|
||||||
"treeline",
|
"termtree",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -417,9 +417,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
version = "1.0.9"
|
version = "1.0.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
@ -558,6 +558,12 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "shell-words"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6fa3938c99da4914afedd13bf3d79bcb6c277d1b2c398d23257a304d9e1b074"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static_assertions"
|
name = "static_assertions"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|
@ -572,9 +578,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.76"
|
version = "1.0.80"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84"
|
checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
@ -610,6 +616,12 @@ dependencies = [
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termtree"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "78fbf2dd23e79c28ccfa2472d3e6b3b189866ffef1aeb91f17c2d968b6586378"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "textwrap"
|
name = "textwrap"
|
||||||
version = "0.14.2"
|
version = "0.14.2"
|
||||||
|
|
@ -619,12 +631,6 @@ dependencies = [
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "treeline"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-segmentation"
|
name = "unicode-segmentation"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
|
@ -633,9 +639,9 @@ checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-xid"
|
name = "unicode-xid"
|
||||||
|
|
@ -707,6 +713,15 @@ version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
|
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "xtask"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"clap",
|
||||||
|
"shell-words",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zoxide"
|
name = "zoxide"
|
||||||
version = "0.7.5"
|
version = "0.7.5"
|
||||||
|
|
|
||||||
13
Cargo.toml
13
Cargo.toml
|
|
@ -9,6 +9,9 @@ license = "MIT"
|
||||||
keywords = ["cli"]
|
keywords = ["cli"]
|
||||||
categories = ["command-line-utilities", "filesystem"]
|
categories = ["command-line-utilities", "filesystem"]
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = ["xtask/"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.32"
|
anyhow = "1.0.32"
|
||||||
askama = { version = "0.10.3", default-features = false }
|
askama = { version = "0.10.3", default-features = false }
|
||||||
|
|
@ -27,17 +30,17 @@ rand = { version = "0.8.4", features = [
|
||||||
"small_rng",
|
"small_rng",
|
||||||
], default-features = false }
|
], default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
assert_cmd = "2.0.0"
|
|
||||||
rstest = "0.11.0"
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
clap = "=3.0.0-beta.4"
|
clap = "=3.0.0-beta.4"
|
||||||
clap_generate = "=3.0.0-beta.4"
|
clap_generate = "=3.0.0-beta.4"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
assert_cmd = "2.0.0"
|
||||||
|
rstest = "0.11.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
nix_tests = []
|
nix = []
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ make_template!(Powershell, "powershell.txt");
|
||||||
make_template!(Xonsh, "xonsh.txt");
|
make_template!(Xonsh, "xonsh.txt");
|
||||||
make_template!(Zsh, "zsh.txt");
|
make_template!(Zsh, "zsh.txt");
|
||||||
|
|
||||||
#[cfg(feature = "nix_tests")]
|
#[cfg(feature = "nix")]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ function __zoxide_cd
|
||||||
{%- if echo %}
|
{%- if echo %}
|
||||||
and __zoxide_pwd
|
and __zoxide_pwd
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
and builtin commandline -f repaint
|
|
||||||
end
|
end
|
||||||
|
|
||||||
{{ section }}
|
{{ section }}
|
||||||
|
|
@ -124,6 +123,7 @@ end
|
||||||
|
|
||||||
__zoxide_unset {{cmd}}
|
__zoxide_unset {{cmd}}
|
||||||
alias {{cmd}}=__zoxide_z
|
alias {{cmd}}=__zoxide_z
|
||||||
|
complete -e {{cmd}}
|
||||||
complete -c {{cmd}} -f -a '(__zoxide_z_complete)'
|
complete -c {{cmd}} -f -a '(__zoxide_z_complete)'
|
||||||
|
|
||||||
__zoxide_unset {{cmd}}i
|
__zoxide_unset {{cmd}}i
|
||||||
|
|
|
||||||
|
|
@ -1,170 +0,0 @@
|
||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 3
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autocfg"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "1.3.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap"
|
|
||||||
version = "3.0.0-beta.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fcd70aa5597dbc42f7217a543f9ef2768b2ef823ba29036072d30e1d88e98406"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"clap_derive",
|
|
||||||
"indexmap",
|
|
||||||
"lazy_static",
|
|
||||||
"os_str_bytes",
|
|
||||||
"textwrap",
|
|
||||||
"vec_map",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clap_derive"
|
|
||||||
version = "3.0.0-beta.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0b5bb0d655624a0b8770d1c178fb8ffcb1f91cc722cb08f451e3dc72465421ac"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.11.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.3.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-segmentation",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "indexmap"
|
|
||||||
version = "1.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
|
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
"hashbrown",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazy_static"
|
|
||||||
version = "1.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "os_str_bytes"
|
|
||||||
version = "3.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6acbef58a60fe69ab50510a55bc8cdd4d6cf2283d27ad338f54cb52747a9cf2d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro-error-attr",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro-error-attr"
|
|
||||||
version = "1.0.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"version_check",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.29"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-xid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "1.0.76"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-xid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "textwrap"
|
|
||||||
version = "0.14.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-segmentation"
|
|
||||||
version = "1.8.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-xid"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "vec_map"
|
|
||||||
version = "0.8.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "version_check"
|
|
||||||
version = "0.9.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "xtask"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"clap",
|
|
||||||
]
|
|
||||||
|
|
@ -2,11 +2,9 @@
|
||||||
name = "xtask"
|
name = "xtask"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
publish = false
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "=3.0.0-beta.4", default-features = false, features = [
|
anyhow = "1.0.32"
|
||||||
"derive",
|
clap = "=3.0.0-beta.4"
|
||||||
"std",
|
shell-words = "1.0.0"
|
||||||
] }
|
|
||||||
|
|
|
||||||
|
|
@ -1,56 +1,104 @@
|
||||||
use std::process::Command;
|
use anyhow::{bail, Context, Result};
|
||||||
|
|
||||||
use clap::Clap;
|
use clap::Clap;
|
||||||
|
|
||||||
#[derive(Clap, Debug)]
|
use std::env;
|
||||||
struct App {
|
use std::ffi::OsStr;
|
||||||
#[clap(subcommand)]
|
use std::path::PathBuf;
|
||||||
task: Task,
|
use std::process::{self, Command};
|
||||||
#[clap(long)]
|
|
||||||
nix: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clap, Debug)]
|
fn main() -> Result<()> {
|
||||||
enum Task {
|
let nix_enabled = enable_nix();
|
||||||
CI,
|
|
||||||
Test { keywords: Vec<String> },
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(args: &[&str], nix: bool) {
|
|
||||||
let args_str = args.join(" ");
|
|
||||||
println!(">>> {}", args_str);
|
|
||||||
|
|
||||||
let status = if nix {
|
|
||||||
Command::new("nix-shell").args(&["--pure", "--run", &args_str]).status()
|
|
||||||
} else {
|
|
||||||
let (cmd, args) = args.split_first().unwrap();
|
|
||||||
Command::new(cmd).args(args).status()
|
|
||||||
};
|
|
||||||
if !status.unwrap().success() {
|
|
||||||
panic!("command exited with an error");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let app = App::parse();
|
let app = App::parse();
|
||||||
let nix = app.nix.unwrap_or_else(|| Command::new("nix-shell").arg("--version").output().is_ok());
|
match app {
|
||||||
let run = |args: &[&str]| run(args, nix);
|
App::Audit => run_audit(&[] as &[&str])?,
|
||||||
match app.task {
|
App::CI => run_ci(nix_enabled)?,
|
||||||
Task::CI => {
|
App::Fmt => run_fmt(&[] as &[&str])?,
|
||||||
let color = if std::env::var_os("CI").is_some() { "--color=always" } else { "" };
|
App::Markdownlint => run_markdownlint()?,
|
||||||
run(&["cargo", "fmt", "--", "--check", color, "--files-with-diff"]);
|
App::Test { args } => run_test(nix_enabled, &args)?,
|
||||||
run(&["cargo", "check", "--all-features", color]);
|
|
||||||
run(&["cargo", "clippy", "--all-features", color, "--", "--deny=clippy::all", "--deny=warnings"]);
|
|
||||||
run(&["cargo", "test", if nix { "--all-features" } else { "" }, color, "--no-fail-fast"]);
|
|
||||||
run(&["cargo", "audit", color, "--deny=warnings"]);
|
|
||||||
if nix {
|
|
||||||
run(&["markdownlint", "--ignore-path=.gitignore", "."]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clap)]
|
||||||
|
enum App {
|
||||||
|
Audit,
|
||||||
|
CI,
|
||||||
|
Fmt,
|
||||||
|
Markdownlint,
|
||||||
|
Test { args: Vec<String> },
|
||||||
|
}
|
||||||
|
|
||||||
|
trait CommandExt {
|
||||||
|
fn _run(self) -> Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CommandExt for &mut Command {
|
||||||
|
fn _run(self) -> Result<()> {
|
||||||
|
println!(">>> {:?}", self);
|
||||||
|
let status = self.status().with_context(|| format!("command failed to start: {:?}", self))?;
|
||||||
|
if !status.success() {
|
||||||
|
bail!("command failed: {:?} with status: {:?}", self, status);
|
||||||
}
|
}
|
||||||
Task::Test { keywords } => {
|
Ok(())
|
||||||
let mut args = vec!["cargo", "test", if nix { "--all-features" } else { "" }, "--no-fail-fast", "--"];
|
|
||||||
args.extend(keywords.iter().map(String::as_str));
|
|
||||||
run(&args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_audit<S: AsRef<OsStr>>(args: &[S]) -> Result<()> {
|
||||||
|
Command::new("cargo").args(&["audit", "--deny=warnings"]).args(args)._run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_clippy<S: AsRef<OsStr>>(args: &[S]) -> Result<()> {
|
||||||
|
Command::new("cargo").args(&["clippy", "--all-features", "--all-targets"]).args(args)._run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_ci(nix_enabled: bool) -> Result<()> {
|
||||||
|
let color = if env::var_os("CI").is_some() { "--color=always" } else { "--color=auto" };
|
||||||
|
run_fmt(&["--check", color, "--files-with-diff"])?;
|
||||||
|
run_clippy(&[color])?;
|
||||||
|
run_test(nix_enabled, &[color, "--no-fail-fast"])?;
|
||||||
|
if nix_enabled {
|
||||||
|
run_audit(&[] as &[&str])?; // FIXME: add "color" when cargo-audit 0.15.3 is released
|
||||||
|
run_markdownlint()?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_fmt<S: AsRef<OsStr>>(rustfmt_args: &[S]) -> Result<()> {
|
||||||
|
Command::new("cargo").args(&["fmt", "--all", "--"]).args(rustfmt_args)._run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_markdownlint() -> Result<()> {
|
||||||
|
Command::new("markdownlint").args(&["--ignore-path=.gitignore", "."])._run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_test<S: AsRef<OsStr>>(nix_enabled: bool, args: &[S]) -> Result<()> {
|
||||||
|
Command::new("cargo")
|
||||||
|
.args(&["test", "--workspace", if nix_enabled { "--features=nix" } else { "" }])
|
||||||
|
.args(args)
|
||||||
|
._run()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enable_nix() -> bool {
|
||||||
|
let nix_supported = cfg!(any(target_os = "linux", target_os = "macos"));
|
||||||
|
if !nix_supported {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let nix_enabled = env::var_os("IN_NIX_SHELL").unwrap_or_default() == "pure";
|
||||||
|
if nix_enabled {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let nix_detected = Command::new("nix-shell").arg("--version").status().map(|s| s.success()).unwrap_or(false);
|
||||||
|
if !nix_detected {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("Detected Nix in environment, re-running in Nix.");
|
||||||
|
let args = env::args();
|
||||||
|
let cmd = shell_words::join(args);
|
||||||
|
let mut nix_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||||
|
nix_path.push("../shell.nix");
|
||||||
|
let status = Command::new("nix-shell").args(&["--pure", "--run", &cmd, "--"]).arg(nix_path).status().unwrap();
|
||||||
|
process::exit(status.code().unwrap_or(1));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue