Skip to content

Commit

Permalink
feat: add shell completions
Browse files Browse the repository at this point in the history
  • Loading branch information
kabouzeid committed Apr 17, 2023
1 parent 682dd7c commit e9b8de0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2021"

[dependencies]
clap = { version = "4.2.2", features = ["derive"] }
clap_complete = "4.2.0"
crossbeam = "0.8.2"
crossterm = "0.25.0"
lazy_static = "1.4.0"
Expand Down
33 changes: 25 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ A text-based user interface (TUI) for the [Slurm Workload Manager](https://slurm

<img alt="turm demo" src="https://user-images.githubusercontent.com/7303830/228503846-3e5abc04-2c1e-422e-844b-d12ca097403a.gif" width="100%" />

`turm` accepts the same CLI flags as `squeue` (see [man squeue](https://slurm.schedmd.com/squeue.html#SECTION_OPTIONS)), and passes them on when querying the jobs.
```bash
turm [--user <username>] [--partition <partition>] [...]
```
`turm` accepts the same options as `squeue` (see [man squeue](https://slurm.schedmd.com/squeue.html#SECTION_OPTIONS)). Use `turm --help` to get a list of all available options.

## Project status

This project is currently a work in progress but the basic functionality is there.
There are still some missing features that need to be implemented and a few visual bugs present at the moment.
Please feel free to submit any issues or feedback you may have.

## Installation

Expand All @@ -24,11 +27,25 @@ cargo install --path .
The [release page](https://github.com/kabouzeid/turm/releases) includes precompiled binaries for Linux, macOS and Windows.
Statically-linked binaries are also available: look for archives with `musl` in the file name.

## Project status
## Shell Completion

This project is currently a work in progress but the basic functionality is there.
There are still some missing features that need to be implemented and a few visual bugs present at the moment.
Please feel free to submit any issues or feedback you may have.
### Bash

In your `.bashrc`, add the following line:
```bash
eval "$(turm completion bash)"
```

### Zsh

In your `.zshrc`, add the following line:
```zsh
eval "$(turm completion zsh)"
```

### Other Shells

Completion scripts for other shells (`fish`, `elvish` and `powershell`) can be generated with `turm completion <shell>`.

## How it works

Expand Down
25 changes: 24 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ mod job_watcher;
mod squeue_args;

use app::App;
use clap::CommandFactory;
use clap::Parser;
use clap::Subcommand;
use clap_complete::{generate, Shell};
use crossbeam::channel::{unbounded, Sender};
use crossterm::{
event::{self, DisableMouseCapture, EnableMouseCapture, Event},
Expand All @@ -18,7 +21,7 @@ use tui::{
Terminal,
};

#[derive(Parser, Debug)]
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Refresh rate for the job watcher.
Expand All @@ -32,10 +35,30 @@ struct Cli {
/// squeue arguments
#[command(flatten)]
squeue_args: SqueueArgs,

#[command(subcommand)]
command: Option<CliCommand>,
}

#[derive(Subcommand)]
enum CliCommand {
/// Print shell completion script to stdout.
Completion {
/// The shell to generate completion for.
shell: Shell,
},
}

fn main() -> Result<(), io::Error> {
let args = Cli::parse();
match args.command {
Some(CliCommand::Completion { shell }) => {
let cmd = &mut Cli::command();
generate(shell, cmd, cmd.get_name().to_string(), &mut io::stdout());
return Ok(());
}
None => {}
}

// setup terminal
enable_raw_mode()?;
Expand Down

0 comments on commit e9b8de0

Please sign in to comment.