-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update deps, generate completions on build, cleanup
- Loading branch information
Showing
13 changed files
with
1,333 additions
and
965 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,19 @@ | ||
use clap::{CommandFactory, ValueEnum}; | ||
use clap_complete::{generate_to, Shell}; | ||
use std::env; | ||
use std::io::Error; | ||
|
||
include!("src/cli.rs"); | ||
|
||
fn main() -> Result<(), Error> { | ||
let completions_dir = env::current_dir()?.join("completions"); | ||
|
||
let mut cmd = Arguments::command(); | ||
|
||
for &shell in Shell::value_variants() { | ||
let path = generate_to(shell, &mut cmd, "thqm", &completions_dir)?; | ||
println!("cargo:warning=completion file is generated: {path:?}"); | ||
} | ||
|
||
Ok(()) | ||
} |
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,58 @@ | ||
|
||
using namespace System.Management.Automation | ||
using namespace System.Management.Automation.Language | ||
|
||
Register-ArgumentCompleter -Native -CommandName 'thqm' -ScriptBlock { | ||
param($wordToComplete, $commandAst, $cursorPosition) | ||
|
||
$commandElements = $commandAst.CommandElements | ||
$command = @( | ||
'thqm' | ||
for ($i = 1; $i -lt $commandElements.Count; $i++) { | ||
$element = $commandElements[$i] | ||
if ($element -isnot [StringConstantExpressionAst] -or | ||
$element.StringConstantType -ne [StringConstantType]::BareWord -or | ||
$element.Value.StartsWith('-') -or | ||
$element.Value -eq $wordToComplete) { | ||
break | ||
} | ||
$element.Value | ||
}) -join ';' | ||
|
||
$completions = @(switch ($command) { | ||
'thqm' { | ||
[CompletionResult]::new('-p', '-p', [CompletionResultType]::ParameterName, 'The port to listen on') | ||
[CompletionResult]::new('--port', '--port', [CompletionResultType]::ParameterName, 'The port to listen on') | ||
[CompletionResult]::new('-U', '-U ', [CompletionResultType]::ParameterName, 'The username to authenticate with') | ||
[CompletionResult]::new('--username', '--username', [CompletionResultType]::ParameterName, 'The username to authenticate with') | ||
[CompletionResult]::new('-P', '-P ', [CompletionResultType]::ParameterName, 'The password to authenticate with') | ||
[CompletionResult]::new('--password', '--password', [CompletionResultType]::ParameterName, 'The password to authenticate with') | ||
[CompletionResult]::new('-S', '-S ', [CompletionResultType]::ParameterName, 'The entry separator') | ||
[CompletionResult]::new('--separator', '--separator', [CompletionResultType]::ParameterName, 'The entry separator') | ||
[CompletionResult]::new('-t', '-t', [CompletionResultType]::ParameterName, 'The page title') | ||
[CompletionResult]::new('--title', '--title', [CompletionResultType]::ParameterName, 'The page title') | ||
[CompletionResult]::new('-s', '-s', [CompletionResultType]::ParameterName, 'The page style') | ||
[CompletionResult]::new('--style', '--style', [CompletionResultType]::ParameterName, 'The page style') | ||
[CompletionResult]::new('--save-qrcode', '--save-qrcode', [CompletionResultType]::ParameterName, 'Save the qrcode image to file') | ||
[CompletionResult]::new('-q', '-q', [CompletionResultType]::ParameterName, 'Show the qrcode in terminal') | ||
[CompletionResult]::new('--qrcode', '--qrcode', [CompletionResultType]::ParameterName, 'Show the qrcode in terminal') | ||
[CompletionResult]::new('-u', '-u', [CompletionResultType]::ParameterName, 'Show the page url') | ||
[CompletionResult]::new('--url', '--url', [CompletionResultType]::ParameterName, 'Show the page url') | ||
[CompletionResult]::new('-o', '-o', [CompletionResultType]::ParameterName, 'Shutdown server after first selection') | ||
[CompletionResult]::new('--oneshot', '--oneshot', [CompletionResultType]::ParameterName, 'Shutdown server after first selection') | ||
[CompletionResult]::new('-c', '-c', [CompletionResultType]::ParameterName, 'Show custom input field') | ||
[CompletionResult]::new('--custom-input', '--custom-input', [CompletionResultType]::ParameterName, 'Show custom input field') | ||
[CompletionResult]::new('--list-styles', '--list-styles', [CompletionResultType]::ParameterName, 'List available page styles') | ||
[CompletionResult]::new('--no-shutdown', '--no-shutdown', [CompletionResultType]::ParameterName, 'Don''t allow the server to be shutdown from the page') | ||
[CompletionResult]::new('--no-qrcode', '--no-qrcode', [CompletionResultType]::ParameterName, 'Don''t allow the qrcode to be shown in the page') | ||
[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') | ||
break | ||
} | ||
}) | ||
|
||
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } | | ||
Sort-Object -Property ListItemText | ||
} |
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
Oops, something went wrong.