-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from donovanglover/feat/man-pages-shell-comple…
…tions feat: add man pages and shell completions
- Loading branch information
Showing
5 changed files
with
159 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
include!("src/cli.rs"); | ||
|
||
use clap::Command; | ||
use clap::CommandFactory; | ||
use clap_complete::generate_to; | ||
use clap_complete::Shell::{Bash, Fish, Zsh}; | ||
use clap_mangen::Man; | ||
use std::fs; | ||
use std::path::PathBuf; | ||
|
||
static NAME: &str = "asak"; | ||
|
||
fn generate_man_pages(cmd: Command) { | ||
let man_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target/man"); | ||
let mut buffer = Vec::default(); | ||
|
||
Man::new(cmd.clone()).render(&mut buffer).unwrap(); | ||
fs::create_dir_all(&man_dir).unwrap(); | ||
fs::write(man_dir.join(NAME.to_owned() + ".1"), buffer).unwrap(); | ||
|
||
for subcommand in cmd.get_subcommands() { | ||
let mut buffer = Vec::default(); | ||
|
||
Man::new(subcommand.clone()).render(&mut buffer).unwrap(); | ||
fs::write( | ||
man_dir.join(NAME.to_owned() + "-" + subcommand.get_name() + ".1"), | ||
buffer, | ||
) | ||
.unwrap(); | ||
} | ||
} | ||
|
||
fn generate_shell_completions(mut cmd: Command) { | ||
let comp_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("target/completions"); | ||
|
||
fs::create_dir_all(&comp_dir).unwrap(); | ||
|
||
for shell in [Bash, Fish, Zsh] { | ||
generate_to(shell, &mut cmd, NAME, &comp_dir).unwrap(); | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut cmd = Cli::command(); | ||
cmd.set_bin_name(NAME); | ||
|
||
generate_man_pages(cmd.clone()); | ||
generate_shell_completions(cmd); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use clap::{Args, Parser, Subcommand}; | ||
|
||
/// Audio Swiss Army knife written in Rust. Like Sox but interactive with TUI. | ||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct Cli { | ||
#[command(subcommand)] | ||
pub command: Commands, | ||
|
||
/// The audio device to use | ||
#[arg(short, long, default_value_t = String::from("default"))] | ||
pub device: String, | ||
|
||
/// Use the JACK host | ||
#[cfg(all( | ||
any( | ||
target_os = "linux", | ||
target_os = "dragonfly", | ||
target_os = "freebsd", | ||
target_os = "netbsd" | ||
), | ||
feature = "jack" | ||
))] | ||
#[arg(short, long)] | ||
#[allow(dead_code)] | ||
pub jack: bool, | ||
} | ||
|
||
#[derive(Debug, Subcommand)] | ||
pub enum Commands { | ||
/// Record an audio file | ||
Rec(RecArgs), | ||
/// Play an audio file | ||
Play(PlayArgs), | ||
/// Monitor audio input with scopes | ||
Monitor(MonitorArgs), | ||
} | ||
|
||
/// Arguments used for the `rec` command | ||
#[derive(Args, Debug)] | ||
pub struct RecArgs { | ||
/// Path for the output audio file, e.g. `output` | ||
#[arg(required = false)] | ||
pub output: Option<String>, | ||
} | ||
|
||
/// Arguments used for the `play` command | ||
#[derive(Args, Debug)] | ||
pub struct PlayArgs { | ||
/// Path to the audio file to play; must be wav format for now, e.g. `input.wav` | ||
#[arg(required = false)] | ||
pub input: Option<String>, | ||
} | ||
|
||
/// Arguments used for the `monitor` command | ||
#[derive(Args, Debug)] | ||
pub struct MonitorArgs { | ||
/// Buffer size for the audio input monitoring, defaults to 1024, the higher the value the more latency | ||
#[arg(required = false, short, long)] | ||
pub buffer_size: Option<usize>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters