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 4 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
53 changes: 30 additions & 23 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,45 @@ jobs:
os: [ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
exe_suffix: ""
target: x86_64-unknown-linux-musl
archive: tar.gz
- os: windows-latest
exe_suffix: ".exe"
target: x86_64-pc-windows-msvc
archive: zip
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
with:
command: build
args: --release --locked --verbose --target ${{ matrix.target }}
uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --locked --verbose --target ${{ matrix.target }}
- name: Pack for Linux
if: matrix.os == 'ubuntu-latest'
env:
RELEASE_NAME: dotter-${{ matrix.target }}
run: |
mkdir $RELEASE_NAME
cp -r target/${{ matrix.target }}/release/dotter -t $RELEASE_NAME
cp -r completions -t $RELEASE_NAME
tar -zcvf $RELEASE_NAME.${{ matrix.archive }} -C $RELEASE_NAME .
- name: Pack for Windows
if: matrix.os == 'windows-latest'
env:
RELEASE_NAME: dotter-${{ matrix.target }}
run: |
New-Item -ItemType Directory -Path ${env:RELEASE_NAME}
Copy-Item -Path "target\${{ matrix.target }}\release\dotter.exe" -Destination ${env:RELEASE_NAME}
Copy-Item -Path "completions" -Destination ${env:RELEASE_NAME} -Recurse
Compress-Archive -Path "${env:RELEASE_NAME}\*" -DestinationPath "${env:RELEASE_NAME}.${{ matrix.archive }}" -Force
- name: Upload asset
uses: actions/upload-release-asset@v1.0.2
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/')
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 }}
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
files: dotter-${{ matrix.target }}.${{ matrix.archive }}
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: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ license = "Unlicense"
[dependencies]
anyhow = "1.*"
clap = { version = "4.0.26", features = ["derive"] }
clap_complete = "4.0.5"
crossterm = "0.25.0"
diff = "0.1.*"
handlebars = { version = "4.*", features = ["script_helper"] }
Expand All @@ -38,6 +37,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