Skip to content

Commit be7908d

Browse files
authored
Shell completions (#57)
* Add shell completions because I am annoyed * Update install instructions
1 parent d987dbb commit be7908d

5 files changed

Lines changed: 80 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ anyhow = "^1.0.100"
1919
rayon = "^1.10"
2020
arrow = { version = "^57.0.0", features = ["default", "ipc_compression"] }
2121
clap = { version = "^4.5.53", features = ["default", "derive"] }
22+
clap_complete = "^4.5"
2223
datafusion = { git = "https://github.com/apache/datafusion.git", rev = "1cc9bcd52e5901f9085864c032c5f51a1932a075" }
2324
futures = "^0.3.31"
2425
glob = "^0.3.3"

README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ Like its namesake fabric -- light, flowing, and effortlessly elegant -- this too
2020

2121
## 📦 Installation
2222

23-
### From Source
23+
### From Source locally
2424

2525
```bash
2626
cargo install --path .
2727
```
2828

29-
### Binary
30-
31-
> [!NOTE]
32-
> Soooooon....
29+
### From GitHub
3330

3431
```bash
35-
cargo binstall silk-chiffon
32+
cargo install --git https://github.com/acuitymd/silk-chiffon
3633
```
3734

3835
### Releases
@@ -180,6 +177,34 @@ Enable bloom filters for specific columns:
180177
- `--overwrite` - Overwrite existing files
181178
- `--list-outputs <FORMAT>` - List output files after creation (text, json)
182179

180+
### Shell Completions
181+
182+
Generate shell completions for your shell:
183+
184+
```bash
185+
# To add completions for your current shell session only
186+
187+
## zsh
188+
eval "$(silk-chiffon completions zsh)"
189+
190+
## bash
191+
eval "$(silk-chiffon completions bash)"
192+
193+
## fish
194+
silk-chiffon completions fish | source
195+
196+
# To persist completions across sessions
197+
198+
## zsh
199+
echo 'eval "$(silk-chiffon completions zsh)"' >> ~/.zshrc
200+
201+
## bash
202+
echo 'eval "$(silk-chiffon completions bash)"' >> ~/.bashrc
203+
204+
## fish
205+
silk-chiffon completions fish > ~/.config/fish/completions/silk-chiffon.fish
206+
```
207+
183208
## 📚 Examples
184209

185210
### Convert with Sorting

src/lib.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ pub mod utils;
99
use crate::utils::collections::{uniq, uniq_by};
1010
use anyhow::{Result, anyhow};
1111
use arrow::ipc::CompressionType;
12-
use clap::{Args, Parser, Subcommand, ValueEnum};
12+
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum};
13+
use clap_complete::Shell;
1314
use datafusion::config::Dialect;
1415
use parquet::{
1516
basic::{Compression, Encoding, GzipLevel, ZstdLevel},
@@ -29,6 +30,7 @@ pub struct Cli {
2930
}
3031

3132
#[derive(Subcommand, Debug)]
33+
#[allow(clippy::large_enum_variant)]
3234
pub enum Commands {
3335
/// Transform data between formats with optional filtering, sorting, merging, and partitioning.
3436
///
@@ -46,6 +48,34 @@ pub enum Commands {
4648
/// silk-chiffon transform --from-many '*.arrow' --to-many "{{year}}/{{month}}.parquet" --by year,month
4749
#[command(verbatim_doc_comment)]
4850
Transform(TransformCommand),
51+
52+
/// Generate shell completions for your shell.
53+
///
54+
/// To add completions for your current shell session only:
55+
/// zsh: eval "$(silk-chiffon completions zsh)"
56+
/// bash: eval "$(silk-chiffon completions bash)"
57+
/// fish: silk-chiffon completions fish | source
58+
///
59+
/// To persist completions across sessions:
60+
/// zsh: echo 'eval "$(silk-chiffon completions zsh)"' >> ~/.zshrc
61+
/// bash: echo 'eval "$(silk-chiffon completions bash)"' >> ~/.bashrc
62+
/// fish: silk-chiffon completions fish > ~/.config/fish/completions/silk-chiffon.fish
63+
#[command(verbatim_doc_comment)]
64+
Completions {
65+
/// Shell to generate completions for
66+
shell: Shell,
67+
},
68+
}
69+
70+
impl Commands {
71+
pub fn generate_completions(shell: Shell) {
72+
clap_complete::generate(
73+
shell,
74+
&mut Cli::command(),
75+
"silk-chiffon",
76+
&mut std::io::stdout(),
77+
);
78+
}
4979
}
5080

5181
#[derive(ValueEnum, Clone, Copy, Debug, Default, Display)]

src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ use silk_chiffon::{Cli, Commands, commands};
66
async fn main() -> Result<()> {
77
let cli = Cli::parse();
88

9+
// handle completions before anything else since it writes to stdout
10+
if let Commands::Completions { shell } = &cli.command {
11+
Commands::generate_completions(*shell);
12+
return Ok(());
13+
}
14+
915
match cli.command {
1016
Commands::Transform(args) => commands::transform::run(args).await?,
17+
Commands::Completions { .. } => unreachable!(),
1118
};
1219
Ok(())
1320
}

0 commit comments

Comments
 (0)