summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-04-02 12:29:47 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-04-17 10:28:11 +0200
commit07f3c3664312a66c974e2c417722bfd42e5fc051 (patch)
tree3d70dbf0d708545ec00dd6ff19673a02808fc330
parent3d61f687ced3aef078223c8138871adfaeb9a862 (diff)
downloadmullvadvpn-07f3c3664312a66c974e2c417722bfd42e5fc051.tar.xz
mullvadvpn-07f3c3664312a66c974e2c417722bfd42e5fc051.zip
Use conditional compilation for shell completions
-rwxr-xr-xbuild.sh21
-rw-r--r--mullvad-cli/Cargo.toml4
-rw-r--r--mullvad-cli/src/main.rs6
3 files changed, 20 insertions, 11 deletions
diff --git a/build.sh b/build.sh
index b8f3501f01..9d58f3eb9b 100755
--- a/build.sh
+++ b/build.sh
@@ -134,6 +134,18 @@ fi
./wireguard/build-wireguard-go.sh
echo "Building Rust code in release mode using $RUSTC_VERSION..."
+
+if [[ ("$(uname -s)" == "Darwin") || ("$(uname -s)" == "Linux") ]]; then
+ pushd mullvad-cli
+ mkdir -p "$SCRIPT_DIR/dist-assets/shell-completions"
+ for sh in bash zsh; do
+ echo "Generating shell completion script for $sh..."
+ cargo +stable run $CARGO_ARGS --release --features shell-completions -- \
+ shell-completions "$sh" "$SCRIPT_DIR/dist-assets/shell-completions/"
+ done
+ popd
+fi
+
MULLVAD_ADD_MANIFEST="1" cargo +stable build $CARGO_ARGS --release
################################################################################
@@ -198,15 +210,6 @@ fi
./update-relays.sh
-if [[ ("$(uname -s)" == "Darwin") || ("$(uname -s)" == "Linux") ]]; then
- echo "Generating shell completion scripts..."
- mkdir -p "$SCRIPT_DIR/dist-assets/shell-completions"
- for sh in bash zsh; do
- "$CARGO_TARGET_DIR/release/mullvad" shell-completions "$sh" \
- "$SCRIPT_DIR/dist-assets/shell-completions/"
- done
-fi
-
pushd "$SCRIPT_DIR/gui"
echo "Installing JavaScript dependencies..."
diff --git a/mullvad-cli/Cargo.toml b/mullvad-cli/Cargo.toml
index ec51a613e3..4deb3f5cbf 100644
--- a/mullvad-cli/Cargo.toml
+++ b/mullvad-cli/Cargo.toml
@@ -7,6 +7,10 @@ license = "GPL-3.0"
edition = "2018"
publish = false
+[features]
+default = []
+shell-completions = []
+
[[bin]]
name = "mullvad"
path = "src/main.rs"
diff --git a/mullvad-cli/src/main.rs b/mullvad-cli/src/main.rs
index ef91e606c8..3d8d2a4aef 100644
--- a/mullvad-cli/src/main.rs
+++ b/mullvad-cli/src/main.rs
@@ -52,6 +52,8 @@ fn run() -> Result<()> {
let commands = cmds::get_commands();
let app = build_cli(&commands);
+
+ #[cfg(feature = "shell-completions")]
let app = app.subcommand(
clap::SubCommand::with_name("shell-completions")
.about("Generates completion scripts for your shell")
@@ -65,12 +67,12 @@ fn run() -> Result<()> {
clap::Arg::with_name("DIR")
.default_value("./")
.help("Output directory where the shell completions are written"),
- )
- .setting(clap::AppSettings::Hidden),
+ ),
);
let app_matches = app.get_matches();
match app_matches.subcommand() {
+ #[cfg(feature = "shell-completions")]
("shell-completions", Some(sub_matches)) => {
let shell = sub_matches
.value_of("SHELL")