Supporting auto complete and a build-release script
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -68,6 +68,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_complete",
|
||||||
"colored",
|
"colored",
|
||||||
"dirs",
|
"dirs",
|
||||||
"home",
|
"home",
|
||||||
@@ -153,6 +154,15 @@ dependencies = [
|
|||||||
"strsim",
|
"strsim",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_complete"
|
||||||
|
version = "4.5.66"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c757a3b7e39161a4e56f9365141ada2a6c915a8622c408ab6bb4b5d047371031"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.55"
|
version = "4.5.55"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ path = "src/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
# CLI framework
|
# CLI framework
|
||||||
clap = { version = "4.4", features = ["derive", "cargo"] }
|
clap = { version = "4.4", features = ["derive", "cargo"] }
|
||||||
|
clap_complete = "4.4"
|
||||||
|
|
||||||
# Filesystem
|
# Filesystem
|
||||||
dirs = "5.0"
|
dirs = "5.0"
|
||||||
|
|||||||
25
README.md
25
README.md
@@ -290,6 +290,31 @@ constructor injection -- the simplest form of dependency inversion.
|
|||||||
| `anvil board --remove NAME` | Remove a board profile |
|
| `anvil board --remove NAME` | Remove a board profile |
|
||||||
| `anvil board --default NAME` | Set the default board |
|
| `anvil board --default NAME` | Set the default board |
|
||||||
| `anvil refresh [--force] [--file P] [--ignore P] [--unignore P]` | Update project infrastructure |
|
| `anvil refresh [--force] [--file P] [--ignore P] [--unignore P]` | Update project infrastructure |
|
||||||
|
| `anvil completions SHELL` | Generate tab-completion script (bash, zsh, fish, powershell) |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tab Completion
|
||||||
|
|
||||||
|
Anvil can generate shell completion scripts so that pressing Tab completes
|
||||||
|
commands, flags, and arguments:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Bash (add to ~/.bashrc)
|
||||||
|
eval "$(anvil completions bash)"
|
||||||
|
|
||||||
|
# Zsh (add to ~/.zshrc)
|
||||||
|
eval "$(anvil completions zsh)"
|
||||||
|
|
||||||
|
# Fish
|
||||||
|
anvil completions fish > ~/.config/fish/completions/anvil.fish
|
||||||
|
|
||||||
|
# PowerShell (add to $PROFILE)
|
||||||
|
anvil completions powershell | Out-String | Invoke-Expression
|
||||||
|
```
|
||||||
|
|
||||||
|
After setup, `anvil ref<Tab>` completes to `anvil refresh`, and
|
||||||
|
`anvil pin --<Tab>` shows all available flags.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
79
build-release.sh
Normal file
79
build-release.sh
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Build release binaries for distribution
|
||||||
|
# This script builds both Linux and Windows binaries (cross-compile)
|
||||||
|
#
|
||||||
|
# For Windows-only builds, use build-release.ps1 on Windows
|
||||||
|
# For Linux-only builds, comment out the Windows section below
|
||||||
|
set -e
|
||||||
|
|
||||||
|
VERSION=${1:-$(git describe --tags --always)}
|
||||||
|
RELEASE_DIR="release-artifacts"
|
||||||
|
|
||||||
|
echo "Building Anvil $VERSION release binaries..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Clean previous artifacts
|
||||||
|
rm -rf "$RELEASE_DIR"
|
||||||
|
mkdir -p "$RELEASE_DIR"
|
||||||
|
|
||||||
|
# Build Linux binary (optimized)
|
||||||
|
echo "Building Linux x86_64 binary..."
|
||||||
|
cargo build --release
|
||||||
|
strip target/release/anvil
|
||||||
|
|
||||||
|
# Package Linux binary
|
||||||
|
echo "Packaging Linux binaries..."
|
||||||
|
cd target/release
|
||||||
|
tar -czf "../../$RELEASE_DIR/anvil-${VERSION}-linux-x86_64.tar.gz" anvil
|
||||||
|
zip -q "../../$RELEASE_DIR/anvil-${VERSION}-linux-x86_64.zip" anvil
|
||||||
|
cd ../..
|
||||||
|
|
||||||
|
# Build Windows binary (cross-compile)
|
||||||
|
echo ""
|
||||||
|
echo "Building Windows x86_64 binary..."
|
||||||
|
|
||||||
|
# Check if Windows target is installed
|
||||||
|
if ! rustup target list | grep -q "x86_64-pc-windows-gnu (installed)"; then
|
||||||
|
echo "Installing Windows target..."
|
||||||
|
rustup target add x86_64-pc-windows-gnu
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if MinGW is installed
|
||||||
|
if ! command -v x86_64-w64-mingw32-gcc &> /dev/null; then
|
||||||
|
echo "Warning: MinGW not found. Install with: sudo apt install mingw-w64"
|
||||||
|
echo "Skipping Windows build."
|
||||||
|
else
|
||||||
|
cargo build --release --target x86_64-pc-windows-gnu
|
||||||
|
x86_64-w64-mingw32-strip target/x86_64-pc-windows-gnu/release/anvil.exe
|
||||||
|
|
||||||
|
# Package Windows binary
|
||||||
|
echo "Packaging Windows binary..."
|
||||||
|
cd target/x86_64-pc-windows-gnu/release
|
||||||
|
zip -q "../../../$RELEASE_DIR/anvil-${VERSION}-windows-x86_64.zip" anvil.exe
|
||||||
|
cd ../../..
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate checksums
|
||||||
|
echo ""
|
||||||
|
echo "Generating checksums..."
|
||||||
|
cd "$RELEASE_DIR"
|
||||||
|
sha256sum * > SHA256SUMS
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
# Display results
|
||||||
|
echo ""
|
||||||
|
echo "==========================================================="
|
||||||
|
echo " Release artifacts built successfully!"
|
||||||
|
echo "==========================================================="
|
||||||
|
echo ""
|
||||||
|
echo "Artifacts in $RELEASE_DIR/:"
|
||||||
|
ls -lh "$RELEASE_DIR"
|
||||||
|
echo ""
|
||||||
|
echo "Checksums:"
|
||||||
|
cat "$RELEASE_DIR/SHA256SUMS"
|
||||||
|
echo ""
|
||||||
|
echo "Upload these files to your Gitea release:"
|
||||||
|
echo " 1. Go to: Releases -> $VERSION -> Edit Release"
|
||||||
|
echo " 2. Drag and drop files from $RELEASE_DIR/"
|
||||||
|
echo " 3. Save"
|
||||||
|
echo ""
|
||||||
18
src/main.rs
18
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{CommandFactory, Parser, Subcommand};
|
||||||
|
use clap_complete::{generate, Shell};
|
||||||
use colored::*;
|
use colored::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use anvil::version::ANVIL_VERSION;
|
use anvil::version::ANVIL_VERSION;
|
||||||
@@ -167,6 +168,12 @@ enum Commands {
|
|||||||
dir: Option<String>,
|
dir: Option<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Generate shell completion scripts
|
||||||
|
Completions {
|
||||||
|
/// Shell to generate completions for (bash, zsh, fish, powershell)
|
||||||
|
shell: Shell,
|
||||||
|
},
|
||||||
|
|
||||||
/// View pin maps, assign pins, and audit wiring
|
/// View pin maps, assign pins, and audit wiring
|
||||||
Pin {
|
Pin {
|
||||||
/// Capability filter (pwm, analog, spi, i2c, uart, interrupt)
|
/// Capability filter (pwm, analog, spi, i2c, uart, interrupt)
|
||||||
@@ -228,7 +235,11 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
|
// Completions output must be clean -- no banner
|
||||||
|
let is_completions = matches!(cli.command, Commands::Completions { .. });
|
||||||
|
if !is_completions {
|
||||||
print_banner();
|
print_banner();
|
||||||
|
}
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Commands::New { name, template, board, list_templates, list_boards } => {
|
Commands::New { name, template, board, list_templates, list_boards } => {
|
||||||
@@ -352,6 +363,11 @@ fn main() -> Result<()> {
|
|||||||
commands::lib::list_libraries(dir.as_deref())
|
commands::lib::list_libraries(dir.as_deref())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Commands::Completions { shell } => {
|
||||||
|
let mut cmd = Cli::command();
|
||||||
|
generate(shell, &mut cmd, "anvil", &mut std::io::stdout());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Commands::Pin {
|
Commands::Pin {
|
||||||
name, pin, assign, remove, audit, brief,
|
name, pin, assign, remove, audit, brief,
|
||||||
generate, capabilities, init_from, mode, cs, board, dir,
|
generate, capabilities, init_from, mode, cs, board, dir,
|
||||||
|
|||||||
Reference in New Issue
Block a user