Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clap derive #1067

Merged
merged 28 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6655356
Upgrade clap to 3.2
tmccombs Jun 17, 2022
45d6f55
Bump MSRV to 1.56.1
tmccombs Jul 18, 2022
4e7b403
Use clap-derive for option parsing
tmccombs Jun 17, 2022
b7f5f4a
Improve help output after switch to clap-derive
tmccombs Jul 18, 2022
066ce41
Fix case of color options to ls
tmccombs Jul 26, 2022
e6f4805
Fix clippy warnings
tmccombs Jul 26, 2022
ff7336b
clap derive suggestions from epage
tmccombs Sep 8, 2022
a50e417
Add action clap attribute to fixed_strings
tmccombs Sep 9, 2022
f4c34b8
Upgrade to clap 4.0
tmccombs Oct 9, 2022
5b9e302
Support powershell when guessing shell for completions
tmccombs Oct 9, 2022
c41d61e
Merge remote-tracking branch 'upstream/master' into clap-derive
tmccombs Oct 9, 2022
86c3349
Fix name of powershell in guess_shell
tmccombs Oct 9, 2022
aca64c0
Actually test if exec or exec-batch is used
tmccombs Oct 9, 2022
10ecb64
Fix typo in test
tmccombs Oct 11, 2022
bf1a6f6
Update clap depenency version
tmccombs Oct 11, 2022
c0b1470
Update msrv to 1.60
tmccombs Oct 11, 2022
c211588
Fix deprecations from clap 4.0
tmccombs Oct 12, 2022
b6f0088
Change thread option to take u32 instead of usize
tmccombs Oct 12, 2022
aec1256
Fix format
tmccombs Oct 15, 2022
a3622ba
Remove TODO comment
tmccombs Oct 20, 2022
3782278
Improve help output
tmccombs Oct 20, 2022
8500c31
Merge remote-tracking branch 'upstream/master' into clap-derive
tmccombs Nov 1, 2022
36ee44a
Make help output more like what it was before use clap_derive
tmccombs Nov 1, 2022
169d22f
Merge remote-tracking branch 'origin/master' into clap-derive
sharkdp Nov 1, 2022
3f72ef4
Remove outdated TODO comment
sharkdp Nov 1, 2022
ebd48d4
Fix unit tests
sharkdp Nov 1, 2022
55029e8
Minor: add missing full stop
sharkdp Nov 1, 2022
5771e74
Add newlines between options
sharkdp Nov 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CICD

env:
MIN_SUPPORTED_RUST_VERSION: "1.57.0"
MIN_SUPPORTED_RUST_VERSION: "1.60.0"
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"

on:
Expand Down Expand Up @@ -181,6 +181,11 @@ jobs:
command: test
args: --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}}

- name: Generate completions
id: completions
shell: bash
run: make completions

- name: Create tarball
id: package
shell: bash
Expand All @@ -193,7 +198,6 @@ jobs:
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
mkdir -p "${ARCHIVE_DIR}/autocomplete"

# Binary
cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR"
Expand All @@ -205,10 +209,7 @@ jobs:
cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR"

# Autocompletion files
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'*/out/'${{ env.PROJECT_NAME }}.bash' "$ARCHIVE_DIR/autocomplete/"
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'*/out/'${{ env.PROJECT_NAME }}.fish' "$ARCHIVE_DIR/autocomplete/"
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'*/out/'_${{ env.PROJECT_NAME }}.ps1' "$ARCHIVE_DIR/autocomplete/"
cp 'contrib/completion/_fd' "$ARCHIVE_DIR/autocomplete/"
cp -r autocomplete "${ARCHIVE_DIR}"

# base compressed package
pushd "${PKG_STAGING}/" >/dev/null
Expand Down Expand Up @@ -256,9 +257,9 @@ jobs:
gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1"

# Autocompletion files
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'*/out/'${{ env.PROJECT_NAME }}.bash' "${DPKG_DIR}/usr/share/bash-completion/completions/${{ env.PROJECT_NAME }}"
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'*/out/'${{ env.PROJECT_NAME }}.fish' "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ env.PROJECT_NAME }}.fish"
install -Dm644 'contrib/completion/_fd' "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ env.PROJECT_NAME }}"
install -Dm644 'autocomplete/fd.bash' "${DPKG_DIR}/usr/share/bash-completion/completions/${{ env.PROJECT_NAME }}"
install -Dm644 'autocomplete/fd.fish' "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ env.PROJECT_NAME }}.fish"
install -Dm644 'autocomplete/_fd' "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ env.PROJECT_NAME }}"

# README and LICENSE
install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
/autocomplete/
**/*.rs.bk
102 changes: 71 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ name = "fd"
path = "src/main.rs"

[build-dependencies]
clap = { version = "3.1", features = ["cargo"] }
clap_complete = "3.1"
version_check = "0.9"

[dependencies]
Expand All @@ -51,10 +49,11 @@ dirs-next = "2.0"
normpath = "0.3.2"
chrono = "0.4"
once_cell = "1.15.0"
clap_complete = {version = "4.0", optional = true}

[dependencies.clap]
version = "3.1"
features = ["suggestions", "color", "wrap_help", "cargo", "unstable-grouped"]
version = "4.0.12"
features = ["suggestions", "color", "wrap_help", "cargo", "unstable-grouped", "derive"]

[target.'cfg(unix)'.dependencies]
users = "0.11.0"
Expand Down Expand Up @@ -84,4 +83,6 @@ codegen-units = 1

[features]
use-jemalloc = ["jemallocator"]
default = ["use-jemalloc"]
completions = ["clap_complete"]
base = ["use-jemalloc"]
default = ["use-jemalloc", "completions"]
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
PROFILE=release
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked that we could previously generate everything with a cargo build. Is there a specific reason for switching to a Makefile?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See discussion here about generating completions in the build.rs file.

Basically, getting this to work with generating the completions from build.rs was getting complicated. So I needed a way to do something after the build finished. There's probably a cargo plugin that could do this (for example https://github.com/phil-opp/cargo-post), but a makefile seemed like the most straighforward way to do it, and probably wouldn't require installing anything new.

EXE=target/$(PROFILE)/fd
prefix=/usr/local
bindir=$(prefix)/bin
datadir=$(prefix)/share
exe_name=fd

$(EXE): Cargo.toml src/**/*.rs
cargo build --profile $(PROFILE)

.PHONY: completions
completions: autocomplete/fd.bash autocomplete/fd.fish autocomplete/fd.ps1 autocomplete/_fd

comp_dir=@mkdir -p autocomplete

autocomplete/fd.bash: $(EXE)
$(comp_dir)
$(EXE) --gen-completions bash > $@

autocomplete/fd.fish: $(EXE)
$(comp_dir)
$(EXE) --gen-completions fish > $@

autocomplete/fd.ps1: $(EXE)
$(comp_dir)
$(EXE) --gen-completions powershell > $@

autocomplete/_fd: contrib/completion/_fd
$(comp_dir)
cp $< $@

install: $(EXE) completions
install -Dm755 $(EXE) $(DESTDIR)$(bindir)/fd
install -Dm644 autocomplete/fd.bash $(DESTDIR)/$(datadir)/bash-completion/completions/$(exe_name)
install -Dm644 autocomplete/fd.fish $(DESTDIR)/$(datadir)/fish/vendor_completions.d/$(exe_name).fish
install -Dm644 autocomplete/_fd $(DESTDIR)/$(datadir)/zsh/site-functions/_$(exe_name)
install -Dm644 doc/fd.1 $(DESTDIR)/$(datadir)/man/man1/$(exe_name).1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Here, `{}` is a placeholder for the search result. `{.}` is the same, without th
See below for more details on the placeholder syntax.

The terminal output of commands run from parallel threads using `-x` will not be interlaced or garbled,
so `fd -x` can be used to rudimentarily parallelize a task run over many files.
so `fd -x` can be used to rudimentarily parallelize a task run over many files.
An example of this is calculating the checksum of each individual file within a directory.
```
fd -tf -x md5sum > file_checksums.txt
Expand Down Expand Up @@ -612,7 +612,7 @@ chown root:root fd.1.gz
sudo cp fd.1.gz /usr/share/man/man1
sudo cp autocomplete/fd.bash /usr/share/bash-completion/completions/fd
source /usr/share/bash-completion/completions/fd
fd
fd
```

### On macOS
Expand Down
23 changes: 1 addition & 22 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
use std::fs;

use clap_complete::{generate_to, Shell};
use Shell::*;
//use clap_complete::shells::Shel{Bash, Fish, PowerShell, Elvish};

include!("src/app.rs");

fn main() {
let min_version = "1.57";
let min_version = "1.60";

match version_check::is_min_version(min_version) {
Some(true) => {}
Expand All @@ -17,17 +9,4 @@ fn main() {
std::process::exit(1);
}
}

let var = std::env::var_os("SHELL_COMPLETIONS_DIR").or_else(|| std::env::var_os("OUT_DIR"));
let outdir = match var {
None => return,
Some(outdir) => outdir,
};
fs::create_dir_all(&outdir).unwrap();

let mut app = build_app();
// NOTE: zsh completions are hand written in contrib/completion/_fd
for shell in [Bash, PowerShell, Fish, Elvish] {
generate_to(shell, &mut app, "fd", &outdir).unwrap();
}
}
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.57.0"
msrv = "1.60.0"