From dfa05bfdaf9fb49ee8ae6164e4bb0b6b3f6fe0e4 Mon Sep 17 00:00:00 2001 From: Jamy Date: Wed, 25 Sep 2024 12:25:52 +0200 Subject: [PATCH] Add "--quiet" flag for "apply", "install" and "update" subcommands (#64) --- CHANGELOG.md | 4 + README.md | 6 +- contrib/completion/tinty.bash | 6 +- contrib/completion/tinty.elvish | 6 + contrib/completion/tinty.powershell | 173 +++++++++++++++++--------- contrib/completion/tinty.zsh | 6 + src/cli.rs | 21 ++++ src/main.rs | 20 ++- src/operations/apply.rs | 2 +- src/operations/install.rs | 52 ++++++-- src/operations/update.rs | 22 ++-- tests/cli_apply_subcommand_tests.rs | 49 +++++++- tests/cli_install_subcommand_tests.rs | 39 +++++- tests/cli_update_subcommand_tests.rs | 38 +++++- tests/utils.rs | 2 +- 15 files changed, 349 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7421133..3aebc35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Added + +- Add `--quiet` flag for `apply`, `install` and `update` subcommands + ### Fixed - Fix bug where Tinty won't update after custom schemes have been built diff --git a/README.md b/README.md index e8c0278..12f26c5 100644 --- a/README.md +++ b/README.md @@ -160,10 +160,8 @@ The following is a table of the available subcommands for the CLI tool (Tinty), | Subcommand | Description | Arguments | Example Usage | |------------|-----------------------------------------------------|----------------------|--------------------------------------------| -| `install` | Installs requirements for the configuration. | - | `tinty install` | | `list` | Lists all available themes. | Optional argument `--custom-schemes` to list saved custom theme files using `tinty generate-scheme` | `tinty list` | | `apply` | Applies a specific theme. | `-`: Name of the system and scheme to apply. | `tinty apply base16-mocha` | -| `update` | Updates the templates and schemes. | - | `tinty update` | | `init` | Initializes the tool with the last applied theme otherwise `default-scheme` from `config.toml`. | - | `tinty init` | | `current` | Displays the currently applied theme. | - | `tinty current` | | `config` | Displays config related information currently in use by Tinty. Without flags it returns `config.yml` content. | - | `tinty config` | @@ -171,6 +169,8 @@ The following is a table of the available subcommands for the CLI tool (Tinty), | `build` | Builds the provided base16 or base24 template using [tinted-builder-rust]. | ``: Path to the base16 or base24 template directory. | `tinty build path/to/tinted-tmux` | | `generate-completion` | Generates a shell completion file to source in your shell startup file (`*rc`). | ``: Name of the shell to generate a completion script for. Supports `bash`, `elvish`, `fish`, `powershell`, `zsh` | `tinty generate-completion bash` | | `generate-scheme` | Generates a yaml scheme file with colors inferred from provided image. | ``: Path to image. Either `` (`-` value to print to stdout) or `--save` to save for use within `tinty` | `tinty generate-completion bash` | +| `install` | Installs requirements for the configuration. | - | `tinty install` | +| `update` | Updates the templates and schemes. | - | `tinty update` | Some subcommands support additional flags and options to modify their behavior: @@ -183,7 +183,7 @@ Some subcommands support additional flags and options to modify their behavior: | `--config-path` | Shows the config.yml path. | `config` | - | `tinty config --config-path` | | `--data-dir-path` | Shows the data directory path. | `config` | - | `tinty config --data-dir-path` | | `--custom-schemes` | Lists saved custom theme files manually created or generated by `tinty generate-scheme` | `list` | - | `tinty list --custom-schemes` | -| `--quiet` | Silences stdout and stderr printing | `build` | - | `tinty build . --quiet` | +| `--quiet` | Boolean flag which silences stdout prints | `apply`, `build`, `install`, `update` | `false` | `tinty build . --quiet` | ## Configuration diff --git a/contrib/completion/tinty.bash b/contrib/completion/tinty.bash index c11c464..5ed5d2a 100644 --- a/contrib/completion/tinty.bash +++ b/contrib/completion/tinty.bash @@ -121,7 +121,7 @@ _tinty() { return 0 ;; tinty__apply) - opts="-c -d -h --config --data-dir --help $($1 list)" + opts="-q -c -d -h --quiet --config --data-dir --help $($1 list)" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -578,7 +578,7 @@ _tinty() { return 0 ;; tinty__install) - opts="-c -d -h --config --data-dir --help" + opts="-q -c -d -h --quiet --config --data-dir --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -638,7 +638,7 @@ _tinty() { return 0 ;; tinty__update) - opts="-c -d -h --config --data-dir --help" + opts="-q -c -d -h --quiet --config --data-dir --help" if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/contrib/completion/tinty.elvish b/contrib/completion/tinty.elvish index 559033c..f7efd7e 100644 --- a/contrib/completion/tinty.elvish +++ b/contrib/completion/tinty.elvish @@ -121,6 +121,8 @@ set edit:completion:arg-completer[tinty] = {|@words| cand --config 'Optional path to the tinty config.toml file' cand -d 'Optional path to the tinty data directory' cand --data-dir 'Optional path to the tinty data directory' + cand -q 'Silence stdout' + cand --quiet 'Silence stdout' cand -h 'Print help' cand --help 'Print help' } @@ -129,6 +131,8 @@ set edit:completion:arg-completer[tinty] = {|@words| cand --config 'Optional path to the tinty config.toml file' cand -d 'Optional path to the tinty data directory' cand --data-dir 'Optional path to the tinty data directory' + cand -q 'Silence stdout' + cand --quiet 'Silence stdout' cand -h 'Print help' cand --help 'Print help' } @@ -137,6 +141,8 @@ set edit:completion:arg-completer[tinty] = {|@words| cand --config 'Optional path to the tinty config.toml file' cand -d 'Optional path to the tinty data directory' cand --data-dir 'Optional path to the tinty data directory' + cand -q 'Silence stdout' + cand --quiet 'Silence stdout' cand -h 'Print help' cand --help 'Print help' } diff --git a/contrib/completion/tinty.powershell b/contrib/completion/tinty.powershell index 8a8c15a..e7d66f2 100644 --- a/contrib/completion/tinty.powershell +++ b/contrib/completion/tinty.powershell @@ -21,115 +21,173 @@ Register-ArgumentCompleter -Native -CommandName 'tinty' -ScriptBlock { $completions = @(switch ($command) { 'tinty' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') - [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version') + [CompletionResult]::new('--version', '--version', [CompletionResultType]::ParameterName, 'Print version') + [CompletionResult]::new('build', 'build', [CompletionResultType]::ParameterValue, 'Builds the target theme template') [CompletionResult]::new('current', 'current', [CompletionResultType]::ParameterValue, 'Prints the last scheme name applied') [CompletionResult]::new('generate-completion', 'generate-completion', [CompletionResultType]::ParameterValue, 'Generates a shell completion script') + [CompletionResult]::new('generate-scheme', 'generate-scheme', [CompletionResultType]::ParameterValue, 'Generates a scheme based on an image') [CompletionResult]::new('info', 'info', [CompletionResultType]::ParameterValue, 'Shows scheme colors for all schemes matching - (Eg: tinty info base16-mocha)') [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initializes with the exising config. Used to Initialize exising theme for when your shell starts up') [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'Lists available schemes') + [CompletionResult]::new('config', 'config', [CompletionResultType]::ParameterValue, 'Provides config related information') [CompletionResult]::new('apply', 'apply', [CompletionResultType]::ParameterValue, 'Applies a theme based on the chosen scheme') [CompletionResult]::new('install', 'install', [CompletionResultType]::ParameterValue, 'Install the environment needed for tinty') [CompletionResult]::new('update', 'update', [CompletionResultType]::ParameterValue, 'Update to the latest themes') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } + 'tinty;build' { + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('--quiet', '--quiet', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } 'tinty;current' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;generate-completion' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'tinty;generate-scheme' { + [CompletionResult]::new('--author', '--author', [CompletionResultType]::ParameterName, 'Scheme author info (name, email, etc) to write, defaults to ''Tinty''') + [CompletionResult]::new('--name', '--name', [CompletionResultType]::ParameterName, 'Scheme display name (can include spaces and capitalization). Defaults to ''Tinty Generated''') + [CompletionResult]::new('--slug', '--slug', [CompletionResultType]::ParameterName, 'Scheme slug (the name you specify when applying schemes). Can not contain white-space or capitalization. Defaults to ''tinty-generated''') + [CompletionResult]::new('--system', '--system', [CompletionResultType]::ParameterName, 'Whether to generate a base16 or base24 scheme') + [CompletionResult]::new('--variant', '--variant', [CompletionResultType]::ParameterName, 'Whether to generate a dark or light scheme') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--save', '--save', [CompletionResultType]::ParameterName, 'Whether to add the scheme to the installed schemes.') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;info' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--custom-schemes', '--custom-schemes', [CompletionResultType]::ParameterName, 'Lists availabile custom schemes') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;init' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--verbose', '--verbose', [CompletionResultType]::ParameterName, 'Print to stdout') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;list' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--custom-schemes', '--custom-schemes', [CompletionResultType]::ParameterName, 'Lists availabile custom schemes') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') + break + } + 'tinty;config' { + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--config-path', '--config-path', [CompletionResultType]::ParameterName, 'Returns path to the tinty config file') + [CompletionResult]::new('--data-dir-path', '--data-dir-path', [CompletionResultType]::ParameterName, 'Returns path to the tinty data directory') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;apply' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('--quiet', '--quiet', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;install' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('--quiet', '--quiet', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;update' { - [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') - [CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('--data-dir', 'data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('--config', '--config', [CompletionResultType]::ParameterName, 'Optional path to the tinty config.toml file') + [CompletionResult]::new('-d', '-d', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('--data-dir', '--data-dir', [CompletionResultType]::ParameterName, 'Optional path to the tinty data directory') + [CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('--quiet', '--quiet', [CompletionResultType]::ParameterName, 'Silence stdout') + [CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help') break } 'tinty;help' { + [CompletionResult]::new('build', 'build', [CompletionResultType]::ParameterValue, 'Builds the target theme template') [CompletionResult]::new('current', 'current', [CompletionResultType]::ParameterValue, 'Prints the last scheme name applied') [CompletionResult]::new('generate-completion', 'generate-completion', [CompletionResultType]::ParameterValue, 'Generates a shell completion script') + [CompletionResult]::new('generate-scheme', 'generate-scheme', [CompletionResultType]::ParameterValue, 'Generates a scheme based on an image') [CompletionResult]::new('info', 'info', [CompletionResultType]::ParameterValue, 'Shows scheme colors for all schemes matching - (Eg: tinty info base16-mocha)') [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initializes with the exising config. Used to Initialize exising theme for when your shell starts up') [CompletionResult]::new('list', 'list', [CompletionResultType]::ParameterValue, 'Lists available schemes') + [CompletionResult]::new('config', 'config', [CompletionResultType]::ParameterValue, 'Provides config related information') [CompletionResult]::new('apply', 'apply', [CompletionResultType]::ParameterValue, 'Applies a theme based on the chosen scheme') [CompletionResult]::new('install', 'install', [CompletionResultType]::ParameterValue, 'Install the environment needed for tinty') [CompletionResult]::new('update', 'update', [CompletionResultType]::ParameterValue, 'Update to the latest themes') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } + 'tinty;help;build' { + break + } 'tinty;help;current' { break } 'tinty;help;generate-completion' { break } + 'tinty;help;generate-scheme' { + break + } 'tinty;help;info' { break } @@ -139,6 +197,9 @@ Register-ArgumentCompleter -Native -CommandName 'tinty' -ScriptBlock { 'tinty;help;list' { break } + 'tinty;help;config' { + break + } 'tinty;help;apply' { break } diff --git a/contrib/completion/tinty.zsh b/contrib/completion/tinty.zsh index 978a290..87953b1 100644 --- a/contrib/completion/tinty.zsh +++ b/contrib/completion/tinty.zsh @@ -136,6 +136,8 @@ _arguments "${_arguments_options[@]}" : \ '--config=[Optional path to the tinty config.toml file]:FILE: ' \ '-d+[Optional path to the tinty data directory]:DIRECTORY: ' \ '--data-dir=[Optional path to the tinty data directory]:DIRECTORY: ' \ +'-q[Silence stdout]' \ +'--quiet[Silence stdout]' \ '-h[Print help]' \ '--help[Print help]' \ ':scheme_name -- The scheme you want to apply:' \ @@ -147,6 +149,8 @@ _arguments "${_arguments_options[@]}" : \ '--config=[Optional path to the tinty config.toml file]:FILE: ' \ '-d+[Optional path to the tinty data directory]:DIRECTORY: ' \ '--data-dir=[Optional path to the tinty data directory]:DIRECTORY: ' \ +'-q[Silence stdout]' \ +'--quiet[Silence stdout]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 @@ -157,6 +161,8 @@ _arguments "${_arguments_options[@]}" : \ '--config=[Optional path to the tinty config.toml file]:FILE: ' \ '-d+[Optional path to the tinty data directory]:DIRECTORY: ' \ '--data-dir=[Optional path to the tinty data directory]:DIRECTORY: ' \ +'-q[Silence stdout]' \ +'--quiet[Silence stdout]' \ '-h[Print help]' \ '--help[Print help]' \ && ret=0 diff --git a/src/cli.rs b/src/cli.rs index b95717f..0bdb8bb 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -177,13 +177,34 @@ pub fn build_cli() -> Command { Arg::new("scheme_name") .help("The scheme you want to apply") .required(true), + ) + .arg( + Arg::new("quiet") + .long("quiet") + .short('q') + .help("Silence stdout") + .action(ArgAction::SetTrue), ), ) .subcommand( Command::new("install").about(format!("Install the environment needed for {}", REPO_NAME)) + .arg( + Arg::new("quiet") + .long("quiet") + .short('q') + .help("Silence stdout") + .action(ArgAction::SetTrue), + ), ) .subcommand( Command::new("update").about("Update to the latest themes") + .arg( + Arg::new("quiet") + .long("quiet") + .short('q') + .help("Silence stdout") + .action(ArgAction::SetTrue), + ), ) } diff --git a/src/main.rs b/src/main.rs index f24a4e7..7a26b78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -131,15 +131,23 @@ fn main() -> Result<()> { let scheme_name = theme.as_str(); operations::apply::apply(&config_path, &data_path, scheme_name, is_quiet) .with_context(|| format!("Failed to apply theme \"{:?}\"", scheme_name))?; - } else { - return Err(anyhow!("scheme_name is required for apply command")); } } - Some(("install", _)) => { - operations::install::install(&config_path, &data_path)?; + Some(("install", sub_matches)) => { + let is_quiet = sub_matches + .get_one::("quiet") + .map(|b| b.to_owned()) + .unwrap_or(false); + + operations::install::install(&config_path, &data_path, is_quiet)?; } - Some(("update", _)) => { - operations::update::update(&config_path, &data_path)?; + Some(("update", sub_matches)) => { + let is_quiet = sub_matches + .get_one::("quiet") + .map(|b| b.to_owned()) + .unwrap_or(false); + + operations::update::update(&config_path, &data_path, is_quiet)?; } Some(("generate-scheme", sub_matches)) => { let slug_default = "tinty-generated".to_string(); diff --git a/src/operations/apply.rs b/src/operations/apply.rs index 5ce2d6a..ea4599c 100644 --- a/src/operations/apply.rs +++ b/src/operations/apply.rs @@ -95,7 +95,7 @@ pub fn apply( (true, true) => { let scheme_partial_name = &scheme_name_arr[1..].join("-"); - Err(anyhow!("You have a Tinty generated scheme named the same as an official scheme name, please rename or remove it: {}", format!("{}/{}.yaml", custom_schemes_path.display(), scheme_partial_name))) + Err(anyhow!("You have a Tinty generated scheme named the same as an official tinted-theming/schemes name, please rename or remove it: {}", format!("{}/{}.yaml", custom_schemes_path.display(), scheme_partial_name))) } _ => Err(anyhow!("Scheme does not exist: {}", full_scheme_name)), } diff --git a/src/operations/install.rs b/src/operations/install.rs index 15140ec..b5c8c8e 100644 --- a/src/operations/install.rs +++ b/src/operations/install.rs @@ -7,19 +7,31 @@ use std::os::unix::fs::symlink; use std::path::{Path, PathBuf}; use url::Url; -fn install_git_url(data_item_path: &Path, item_name: &str, item_git_url: &str) -> Result<()> { +fn install_git_url( + data_item_path: &Path, + item_name: &str, + item_git_url: &str, + is_quiet: bool, +) -> Result<()> { if !data_item_path.is_dir() { git_clone(item_git_url, data_item_path)?; - println!("{} installed", item_name); - } else { + if !is_quiet { + println!("{} installed", item_name); + } + } else if !is_quiet { println!("{} already installed", item_name); } Ok(()) } -fn install_dir(data_item_path: &Path, item_name: &str, item_path: &Path) -> Result<()> { +fn install_dir( + data_item_path: &Path, + item_name: &str, + item_path: &Path, + is_quiet: bool, +) -> Result<()> { if item_path.exists() && !item_path.is_dir() { return Err(anyhow!( "{} is not a symlink to a directory. Please remove it and try again", @@ -35,17 +47,22 @@ fn install_dir(data_item_path: &Path, item_name: &str, item_path: &Path) -> Resu return Err(anyhow!("Error trying to remove symlink at \"{}\". Remove it manually and try again", data_item_path.display())); } symlink(item_path, data_item_path)?; - println!("{} already installed", item_name); + + if !is_quiet { + println!("{} already installed", item_name); + } } } Err(_) => { - println!("err"); return Err(anyhow!("\"{}\" is a not a symlink, but according to your config it should be. Please remove this directory and try again", data_item_path.display())); } } } else { symlink(item_path, data_item_path)?; - println!("{} installed", item_name); + + if !is_quiet { + println!("{} installed", item_name); + } } Ok(()) @@ -55,8 +72,7 @@ fn install_dir(data_item_path: &Path, item_name: &str, item_path: &Path) -> Resu /// /// Clones the provided config repositories and ensures everything is ready for when the user runs /// any other command -pub fn install(config_path: &Path, data_path: &Path) -> Result<()> { - // Hooks +pub fn install(config_path: &Path, data_path: &Path, is_quiet: bool) -> Result<()> { let config = Config::read(config_path)?; let items = config.items.unwrap_or_default(); let hooks_path = data_path.join(REPO_DIR); @@ -66,14 +82,24 @@ pub fn install(config_path: &Path, data_path: &Path) -> Result<()> { let item_path = PathBuf::from(item.path.as_str()); match Url::parse(item.path.as_str()) { - Ok(_) => install_git_url(&data_item_path, item.name.as_str(), item.path.as_str())?, - Err(_) => install_dir(&data_item_path, item.name.as_str(), &item_path)?, + Ok(_) => install_git_url( + &data_item_path, + item.name.as_str(), + item.path.as_str(), + is_quiet, + )?, + Err(_) => install_dir(&data_item_path, item.name.as_str(), &item_path, is_quiet)?, } } - // Schemes let schemes_repo_path = hooks_path.join(SCHEMES_REPO_NAME); - install_git_url(&schemes_repo_path, SCHEMES_REPO_NAME, SCHEMES_REPO_URL)?; + + install_git_url( + &schemes_repo_path, + SCHEMES_REPO_NAME, + SCHEMES_REPO_URL, + is_quiet, + )?; Ok(()) } diff --git a/src/operations/update.rs b/src/operations/update.rs index 21d56fb..0ea4852 100644 --- a/src/operations/update.rs +++ b/src/operations/update.rs @@ -4,7 +4,7 @@ use crate::{config::Config, constants::REPO_NAME}; use anyhow::{Context, Result}; use std::path::Path; -fn update_item(item_name: &str, item_url: &str, item_path: &Path) -> Result<()> { +fn update_item(item_name: &str, item_url: &str, item_path: &Path, is_quiet: bool) -> Result<()> { if item_path.is_dir() { let is_diff = git_diff(item_path)?; @@ -12,11 +12,13 @@ fn update_item(item_name: &str, item_url: &str, item_path: &Path) -> Result<()> git_pull(item_path) .with_context(|| format!("Error pulling {} from {}", item_name, item_url))?; - println!("{} up to date", item_name); - } else { + if !is_quiet { + println!("{} up to date", item_name); + } + } else if !is_quiet { println!("{} contains uncommitted changes, please commit or remove and then run `{} update` again.", item_name, REPO_NAME); } - } else { + } else if !is_quiet { println!("{} not installed (run `{} install`)", item_name, REPO_NAME); } @@ -26,7 +28,7 @@ fn update_item(item_name: &str, item_url: &str, item_path: &Path) -> Result<()> /// Updates local files /// /// Updates the provided repositories in config file by doing a git pull -pub fn update(config_path: &Path, data_path: &Path) -> Result<()> { +pub fn update(config_path: &Path, data_path: &Path, is_quiet: bool) -> Result<()> { let config = Config::read(config_path)?; let items = config.items.unwrap_or_default(); let hooks_path = data_path.join(REPO_DIR); @@ -34,13 +36,17 @@ pub fn update(config_path: &Path, data_path: &Path) -> Result<()> { for item in items { let item_path = hooks_path.join(&item.name); - update_item(item.name.as_str(), item.path.as_str(), &item_path)?; + update_item(item.name.as_str(), item.path.as_str(), &item_path, is_quiet)?; } - // Schemes let schemes_repo_path = hooks_path.join(SCHEMES_REPO_NAME); - update_item(SCHEMES_REPO_NAME, SCHEMES_REPO_URL, &schemes_repo_path)?; + update_item( + SCHEMES_REPO_NAME, + SCHEMES_REPO_URL, + &schemes_repo_path, + is_quiet, + )?; Ok(()) } diff --git a/tests/cli_apply_subcommand_tests.rs b/tests/cli_apply_subcommand_tests.rs index 399fac4..6fb95e3 100644 --- a/tests/cli_apply_subcommand_tests.rs +++ b/tests/cli_apply_subcommand_tests.rs @@ -176,9 +176,6 @@ fn test_cli_apply_subcommand_with_custom_schemes() -> Result<()> { "test_cli_apply_subcommand_with_custom_schemes", format!("apply {}", &scheme_name_with_system).as_str(), )?; - let config_content = r##" -hooks = ["echo 'Path: %f'"] -"##; let custom_scheme_file_path = data_path.join(format!("custom-schemes/base16/{}.yaml", scheme_name)); let expected_output = format!( @@ -189,7 +186,6 @@ hooks = ["echo 'Path: %f'"] let scheme_content = fs::read_to_string(Path::new("./tests/fixtures/schemes/tinty-generated.yaml"))?; write_to_file(&custom_scheme_file_path, &scheme_content)?; - write_to_file(&config_path, config_content)?; // --- // Act @@ -217,6 +213,51 @@ hooks = ["echo 'Path: %f'"] Ok(()) } +#[test] +fn test_cli_apply_subcommand_with_custom_schemes_quiet_flag() -> Result<()> { + // ------- + // Arrange + // ------- + let scheme_system = "base16"; + let scheme_name = "tinty-generated"; + let scheme_name_with_system = format!("{}-{}", scheme_system, scheme_name); + let (config_path, data_path, command_vec, cleanup) = setup( + "test_cli_apply_subcommand_with_custom_schemes_quiet_flag", + format!("apply {} --quiet", &scheme_name_with_system).as_str(), + )?; + let custom_scheme_file_path = + data_path.join(format!("custom-schemes/base16/{}.yaml", scheme_name)); + let current_scheme_path = data_path.join(CURRENT_SCHEME_FILE_NAME); + let scheme_content = + fs::read_to_string(Path::new("./tests/fixtures/schemes/tinty-generated.yaml"))?; + write_to_file(&custom_scheme_file_path, &scheme_content)?; + + // --- + // Act + // --- + utils::run_install_command(&config_path, &data_path)?; + let (stdout, stderr) = utils::run_command(command_vec).unwrap(); + + // ------ + // Assert + // ------ + assert_eq!( + fs::read_to_string(current_scheme_path)?, + scheme_name_with_system, + ); + assert!( + stdout.is_empty(), + "stdout does not contain the expected output" + ); + assert!( + stderr.is_empty(), + "stderr does not contain the expected output" + ); + + cleanup()?; + Ok(()) +} + #[test] fn test_cli_apply_subcommand_root_hooks_with_setup() -> Result<()> { // ------- diff --git a/tests/cli_install_subcommand_tests.rs b/tests/cli_install_subcommand_tests.rs index dce49c7..bcc7c79 100644 --- a/tests/cli_install_subcommand_tests.rs +++ b/tests/cli_install_subcommand_tests.rs @@ -113,7 +113,7 @@ fn test_cli_install_subcommand_with_setup() -> Result<()> { // Act // --- utils::run_command(command_vec.clone()).unwrap(); - let (stdout, _) = utils::run_command(command_vec).unwrap(); + let (stdout, stderr) = utils::run_command(command_vec).unwrap(); // ------ // Assert @@ -123,6 +123,43 @@ fn test_cli_install_subcommand_with_setup() -> Result<()> { stdout.contains(expected_output), "stdout does not contain the expected output" ); + assert!( + stderr.is_empty(), + "stderr does not contain the expected output" + ); + + cleanup()?; + Ok(()) +} + +#[test] +fn test_cli_install_subcommand_with_setup_quiet_flag() -> Result<()> { + // ------- + // Arrange + // ------- + let (_, _, command_vec, cleanup) = setup( + "test_cli_install_subcommand_with_setup_quiet_flag", + "install --quiet", + )?; + + // --- + // Act + // --- + utils::run_command(command_vec.clone()).unwrap(); + let (stdout, stderr) = utils::run_command(command_vec).unwrap(); + + // ------ + // Assert + // ------ + + assert!( + stdout.is_empty(), + "stdout does not contain the expected output" + ); + assert!( + stderr.is_empty(), + "stderr does not contain the expected output" + ); cleanup()?; Ok(()) diff --git a/tests/cli_update_subcommand_tests.rs b/tests/cli_update_subcommand_tests.rs index 9445fc9..cc7dfe0 100644 --- a/tests/cli_update_subcommand_tests.rs +++ b/tests/cli_update_subcommand_tests.rs @@ -44,7 +44,7 @@ fn test_cli_update_subcommand_with_setup() -> Result<()> { // Act // --- utils::run_install_command(&config_path, &data_path)?; - let (stdout, _) = utils::run_command(command_vec).unwrap(); + let (stdout, stderr) = utils::run_command(command_vec).unwrap(); // ------ // Assert @@ -54,6 +54,42 @@ fn test_cli_update_subcommand_with_setup() -> Result<()> { stdout.contains(expected_output), "stdout does not contain the expected output" ); + assert!( + stderr.is_empty(), + "stderr does not contain the expected output" + ); + + Ok(()) +} + +#[test] +fn test_cli_update_subcommand_with_setup_quiet_flag() -> Result<()> { + // ------- + // Arrange + // ------- + let (config_path, data_path, command_vec, cleanup) = setup( + "test_cli_update_subcommand_with_setup_quiet_flag", + "update --quiet", + )?; + + // --- + // Act + // --- + utils::run_install_command(&config_path, &data_path)?; + let (stdout, stderr) = utils::run_command(command_vec).unwrap(); + + // ------ + // Assert + // ------ + cleanup()?; + assert!( + stdout.is_empty(), + "stdout does not contain the expected output" + ); + assert!( + stderr.is_empty(), + "stderr does not contain the expected output" + ); Ok(()) } diff --git a/tests/utils.rs b/tests/utils.rs index 3da36c3..e28ef3a 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -20,7 +20,7 @@ pub fn run_command(command_vec: Vec) -> Result<(String, String), Box