Skip to content

Generate completions at compile-time #118

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

Merged
merged 9 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions .github/workflows/build-for-release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Build assets for a Release

on:
release:
types: [published]
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
build-artifact:
Expand All @@ -12,39 +13,52 @@ jobs:
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
exe_suffix: ""
target: x86_64-unknown-linux-musl
- os: windows-latest
exe_suffix: ".exe"
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
override: true

- name: Cache dependencies
uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
uses: Swatinem/rust-cache@v2

- name: Build
run: cargo build --release --locked --verbose --target ${{ matrix.target }}

- name: Pack completions
if: matrix.os == 'ubuntu-latest' # Runs only once
run: zip -r completions.zip completions

- name: Upload asset on Linux
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-latest'
with:
command: build
args: --release --locked --verbose --target ${{ matrix.target }}
- name: Upload asset
uses: actions/[email protected]
files: |
target/${{ matrix.target }}/release/dotter
completions.zip

- name: Upload asset on Windows
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/') && matrix.os == 'windows-latest'
with:
asset_path: target/${{ matrix.target }}/release/dotter${{ matrix.exe_suffix }}
asset_name: dotter${{ matrix.exe_suffix }}
asset_content_type: application/octet-stream
upload_url: ${{ github.event.release.upload_url }}
files: target/${{ matrix.target }}/release/dotter.exe

cargo-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- run: cargo publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- run: cargo publish
11 changes: 11 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ license = "Unlicense"
anyhow = "1.*"
clap = { version = "4.0.26", features = ["derive"] }
clap_complete = "4.0.5"
clap_complete_nushell = "0.1.10"
crossterm = "0.25.0"
diff = "0.1.*"
handlebars = { version = "4.*", features = ["script_helper"] }
Expand All @@ -38,6 +39,11 @@ mockall = "0.11.3"
# Enable this instead for better failure messages (on nightly only)
# mockall = { version = "0.9.*", features = ["nightly"] }

[build-dependencies]
clap = { version = "4.0.26", features = ["derive"] }
clap_complete = "4.0.5"
clap_complete_nushell = "0.1.10"

[target.'cfg(windows)'.dependencies]
dunce = "1.*"

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Commands:
undeploy Delete all deployed files from their target locations. Note that this operates on all files that are currently in cache
init Initialize global.toml with a single package containing all the files in the current directory pointing to a dummy value and a local.toml that selects that package
watch Run continuously, watching the repository for changes and deploying as soon as they happen. Can be ran with `--dry-run`
gen-completions Generate shell completions
Copy link
Owner

Choose a reason for hiding this comment

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

needs revert

help Print this message or the help of the given subcommand(s)

Options:
Expand Down
24 changes: 24 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[path = "src/args.rs"]
mod args;

use self::args::Options;
use clap::CommandFactory;
use clap_complete::generate_to;
use clap_complete::Shell::*;
use clap_complete_nushell::Nushell;
use std::io;

fn main() -> io::Result<()> {
let cmd = &mut Options::command();
let name = "dotter";
let dir = "completions";

generate_to(Bash, cmd, name, dir)?;
generate_to(Zsh, cmd, name, dir)?;
generate_to(Elvish, cmd, name, dir)?;
generate_to(Fish, cmd, name, dir)?;
generate_to(PowerShell, cmd, name, dir)?;
generate_to(Nushell, cmd, name, dir)?;

Ok(())
}
Loading