Skip to content

Commit

Permalink
fix: update deps, generate completions on build, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed Sep 13, 2024
1 parent e571c4e commit 764ba8c
Show file tree
Hide file tree
Showing 13 changed files with 1,333 additions and 965 deletions.
1,640 changes: 992 additions & 648 deletions Cargo.lock

Large diffs are not rendered by default.

40 changes: 22 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ panic = "abort"

[profile.release]
opt-level = "z"
strip=true
strip = true
codegen-units = 1
lto = true
panic = "abort"
Expand All @@ -24,27 +24,31 @@ panic = "abort"
name = "thqm"
path = "src/main.rs"

[features]
completions=["clap_complete"]

[dependencies]
clap = {version="3.0.14", features= ["cargo"] }
clap_complete = {version="3.0.6", optional=true}
dirs = "4.0.0"
anyhow = "1.0.42"
clap = { version = "4.5.17", features = ["derive"] }
dirs = "5.0.1"
anyhow = "1.0.88"
log = "0.4.14"
env_logger = { default-features = false, version = "0.9.0" }
env_logger = { default-features = false, version = "0.11.0" }
flate2 = "1.0.20"
tar = { default-features = false, version = "0.4.35" }
tera = { default-features = false, version = "1" }
qrcode = "0.12.0"
image = {version="0.23.0", features=["jpeg", "png"], default-features = false}
rouille = {version="3.2.1", default-features = false}
local-ip-address = "0.4.4"
tar = { default-features = false, version = "0.4.41" }
tera = { default-features = false, version = "1.20.0" }
qrcode = "0.14.0"
image = { version = "0.25.2", features = [
"jpeg",
"png",
], default-features = false }
rouille = { version = "3.2.1", default-features = false }
local-ip-address = "0.6.2"

[dev-dependencies]
ctor = "0.1.21"
ctor = "0.2.8"
assert_cmd = "2.0.4"
predicates = "2.1.1"
predicates = "3.1.2"
assert_fs = "1.0.7"
reqwest = { version = "0.11.15", features = ["blocking"] }
reqwest = { version = "0.12.7", features = ["blocking"] }

[build-dependencies]
clap = { version = "4.5.17", features = ["derive"] }
clap_complete = { version = "4.5.6" }
anyhow = "1.0.88"
55 changes: 25 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3 align="center">thqm</h1>
<h3 align="center"><img src="https://i.imgur.com/8VpsYG4.png" width="150"></h3>
<h5 align="center">A simple HTTP server to serve a dynamic menu for your scripts over the network.</h5>
<h5 align="center">A simple HTTP server to serve a dynamic menu web page.</h5>
<p align="center">
<a href="https://github.com/loiccoyle/thqm-rs/actions/workflows/build.yml"><img src="https://github.com/loiccoyle/thqm-rs/actions/workflows/build.yml/badge.svg"></a>
<a href="https://crates.io/crates/thqm"><img src="https://img.shields.io/crates/v/thqm.svg"></a>
Expand Down Expand Up @@ -31,9 +31,9 @@ To compile and install manually from this repo, you'll need `rust` installed.
To compile the binary:

```console
$ git clone https://github.com/loiccoyle/thqm-rs
$ cd thqm-rs
$ cargo build --release
git clone https://github.com/loiccoyle/thqm-rs
cd thqm-rs
cargo build --release
```

The compiled binary will be located at `./target/release/thqm`.
Expand All @@ -42,15 +42,15 @@ Just place this binary somewhere in your `$PATH`.
### Cargo

```console
$ cargo install thqm
cargo install thqm
```

### Arch linux (AUR)

Using your favourite AUR helper:

```console
$ paru -S thqm
paru -S thqm
```

## 📋 Usage
Expand All @@ -63,8 +63,6 @@ $ paru -S thqm

```
$ thqm --help
thqm 0.1.6
Loic Coyle <loic.coyle@hotmail.fr>
A simple HTTP server to serve a dynamic menu for your scripts.
thqm serves a menu from standard input and writes selections to standard output.
Expand All @@ -81,28 +79,25 @@ $ echo 'Option 1\nOption 2' | thqm -U |
esac
done
USAGE:
thqm [OPTIONS]
OPTIONS:
--custom-input Show custom input field.
-h, --help Print help information
--interface <interface> Network interface to use to determine ip.
--list-styles List available page styles.
--no-qrcode Don't show the qrcode on the page.
--no-shutdown Don't allow the server to be shutdown from the page.
--oneshot Shutdown server after first selection.
-p, --port <port> Set the server's port. [default: 8000]
-P, --password <password> Authentication password.
-q, --show-qrcode Show the qrcode in terminal.
-s, --style <style> Page style. [default: default] [possible values: base, default,
fa-grid]
-S, --separator <separator> Entry separator. [default: \n]
--save-qrcode <path> Save the qrcode image to file.
-t, --title <title> Page title. [default: thqm]
-u, --username <username> Authentication username. [default: thqm]
-U, --show-url Show the page url.
-V, --version Print version information
Usage: thqm [OPTIONS]
Options:
-p, --port <PORT> The port to listen on [default: 8000]
-U, --username <USERNAME> The username to authenticate with
-P, --password <PASSWORD> The password to authenticate with
-S, --separator <SEPARATOR> The entry separator [default: "\n"]
-t, --title <TITLE> The page title [default: thqm]
-s, --style <STYLE> The page style [default: default]
-q, --qrcode Show the qrcode in terminal
--save-qrcode <PATH> Save the qrcode image to file
-u, --url Show the page url
-o, --oneshot Shutdown server after first selection
-c, --custom-input Show custom input field
--list-styles List available page styles
--no-shutdown Don't allow the server to be shutdown from the page
--no-qrcode Don't allow the qrcode to be shown in the page
-h, --help Print help
-V, --version Print version
```

<!-- help end -->
Expand Down
19 changes: 19 additions & 0 deletions build.rs
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(())
}
63 changes: 34 additions & 29 deletions completions/_thqm
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,35 @@ _thqm() {
fi

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" \
'-p+[Set the server'\''s port.]: : ' \
'--port=[Set the server'\''s port.]: : ' \
'-u+[Authentication username.]: : ' \
'--username=[Authentication username.]: : ' \
'-P+[Authentication password.]: : ' \
'--password=[Authentication password.]: : ' \
'-S+[Entry separator.]: : ' \
'--separator=[Entry separator.]: : ' \
'-t+[Page title.]: : ' \
'--title=[Page title.]: : ' \
'-s+[Page style.]: :($(thqm --list-styles))' \
'--style=[Page style.]: :($(thqm --list-styles))' \
'--interface=[Network interface to use to determine ip.]: : ' \
'--save-qrcode=[Save the qrcode image to file.]: : ' \
'-h[Print help information]' \
'--help[Print help information]' \
'-V[Print version information]' \
'--version[Print version information]' \
'--list-styles[List available page styles.]' \
'-q[Show the qrcode in terminal.]' \
'--show-qrcode[Show the qrcode in terminal.]' \
'-U[Show the page url.]' \
'--show-url[Show the page url.]' \
'--oneshot[Shutdown server after first selection.]' \
'--custom-input[Show custom input field.]' \
'--no-shutdown[Don'\''t allow the server to be shutdown from the page.]' \
'--no-qrcode[Don'\''t show the qrcode on the page.]' \
_arguments "${_arguments_options[@]}" : \
'-p+[The port to listen on]:PORT: ' \
'--port=[The port to listen on]:PORT: ' \
'-U+[The username to authenticate with]:USERNAME: ' \
'--username=[The username to authenticate with]:USERNAME: ' \
'-P+[The password to authenticate with]:PASSWORD: ' \
'--password=[The password to authenticate with]:PASSWORD: ' \
'-S+[The entry separator]:SEPARATOR: ' \
'--separator=[The entry separator]:SEPARATOR: ' \
'-t+[The page title]:TITLE: ' \
'--title=[The page title]:TITLE: ' \
'-s+[The page style]:STYLE: ' \
'--style=[The page style]:STYLE: ' \
'--save-qrcode=[Save the qrcode image to file]:PATH:_files' \
'-q[Show the qrcode in terminal]' \
'--qrcode[Show the qrcode in terminal]' \
'-u[Show the page url]' \
'--url[Show the page url]' \
'-o[Shutdown server after first selection]' \
'--oneshot[Shutdown server after first selection]' \
'-c[Show custom input field]' \
'--custom-input[Show custom input field]' \
'--list-styles[List available page styles]' \
'--no-shutdown[Don'\''t allow the server to be shutdown from the page]' \
'--no-qrcode[Don'\''t allow the qrcode to be shown in the page]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
&& ret=0
}

Expand All @@ -51,4 +52,8 @@ _thqm_commands() {
_describe -t commands 'thqm commands' commands "$@"
}

_thqm "$@"
if [ "$funcstack[1]" = "_thqm" ]; then
_thqm "$@"
else
compdef _thqm thqm
fi
58 changes: 58 additions & 0 deletions completions/_thqm.ps1
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
}
22 changes: 11 additions & 11 deletions completions/thqm → completions/thqm.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_thqm() {
local i cur prev opts cmds
local i cur prev opts cmd
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
Expand All @@ -8,8 +8,8 @@ _thqm() {

for i in ${COMP_WORDS[@]}
do
case "${i}" in
"$1")
case "${cmd},${i}" in
",$1")
cmd="thqm"
;;
*)
Expand All @@ -19,7 +19,7 @@ _thqm() {

case "${cmd}" in
thqm)
opts="-h -V -p -u -P -S -t -s -q -U --help --version --port --username --password --separator --title --style --list-styles --interface --show-qrcode --save-qrcode --show-url --oneshot --custom-input --no-shutdown --no-qrcode"
opts="-p -U -P -S -t -s -q -u -o -c -h -V --port --username --password --separator --title --style --qrcode --save-qrcode --url --oneshot --custom-input --list-styles --no-shutdown --no-qrcode --help --version"
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand All @@ -37,7 +37,7 @@ _thqm() {
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-u)
-U)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
Expand Down Expand Up @@ -66,14 +66,10 @@ _thqm() {
return 0
;;
--style)
COMPREPLY=($(compgen -C "thqm --list-styles" -- "${cur}"))
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
-s)
COMPREPLY=($(compgen -C "thqm --list-styles" -- "${cur}"))
return 0
;;
--interface)
COMPREPLY=($(compgen -f "${cur}"))
return 0
;;
Expand All @@ -91,4 +87,8 @@ _thqm() {
esac
}

complete -F _thqm -o bashdefault -o default thqm
if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then
complete -F _thqm -o nosort -o bashdefault -o default thqm
else
complete -F _thqm -o bashdefault -o default thqm
fi
Loading

0 comments on commit 764ba8c

Please sign in to comment.