-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move generating static assets to a
cargo-xtask
task (#196)
* Move generating static assets to a `cargo-xtask` task * Generate static assets * Remove now unused build dependencies * Fix CI
- Loading branch information
1 parent
1d56bc8
commit c025993
Showing
13 changed files
with
340 additions
and
32 deletions.
There are no files selected for viewing
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,2 @@ | ||
[alias] | ||
xtask = "run --package xtask --" |
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
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,46 @@ | ||
#compdef sd | ||
|
||
autoload -U is-at-least | ||
|
||
_sd() { | ||
typeset -A opt_args | ||
typeset -a _arguments_options | ||
local ret=1 | ||
|
||
if is-at-least 5.2; then | ||
_arguments_options=(-s -S -C) | ||
else | ||
_arguments_options=(-s -C) | ||
fi | ||
|
||
local context curcontext="$curcontext" state line | ||
_arguments "${_arguments_options[@]}" \ | ||
'-n+[Limit the number of replacements]:REPLACEMENTS: ' \ | ||
'-f+[Regex flags. May be combined (like \`-f mc\`).]:FLAGS: ' \ | ||
'--flags=[Regex flags. May be combined (like \`-f mc\`).]:FLAGS: ' \ | ||
'-p[Output result into stdout and do not modify files]' \ | ||
'--preview[Output result into stdout and do not modify files]' \ | ||
'-F[Treat FIND and REPLACE_WITH args as literal strings]' \ | ||
'--fixed-strings[Treat FIND and REPLACE_WITH args as literal strings]' \ | ||
'-r[Recursively replace files]' \ | ||
'-h[Print help (see more with '\''--help'\'')]' \ | ||
'--help[Print help (see more with '\''--help'\'')]' \ | ||
'-V[Print version]' \ | ||
'--version[Print version]' \ | ||
':find -- The regexp or string (if -s) to search for:' \ | ||
':replace_with -- What to replace each match with. Unless in string mode, you may use captured values like $1, $2, etc:' \ | ||
'*::files -- The path to file(s). This is optional - sd can also read from STDIN. {n}{n}Note\: sd modifies files in-place by default. See documentation for examples:_files' \ | ||
&& ret=0 | ||
} | ||
|
||
(( $+functions[_sd_commands] )) || | ||
_sd_commands() { | ||
local commands; commands=() | ||
_describe -t commands 'sd commands' commands "$@" | ||
} | ||
|
||
if [ "$funcstack[1]" = "_sd" ]; then | ||
_sd "$@" | ||
else | ||
compdef _sd sd | ||
fi |
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,42 @@ | ||
|
||
using namespace System.Management.Automation | ||
using namespace System.Management.Automation.Language | ||
|
||
Register-ArgumentCompleter -Native -CommandName 'sd' -ScriptBlock { | ||
param($wordToComplete, $commandAst, $cursorPosition) | ||
|
||
$commandElements = $commandAst.CommandElements | ||
$command = @( | ||
'sd' | ||
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) { | ||
'sd' { | ||
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Limit the number of replacements') | ||
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Regex flags. May be combined (like `-f mc`).') | ||
[CompletionResult]::new('--flags', 'flags', [CompletionResultType]::ParameterName, 'Regex flags. May be combined (like `-f mc`).') | ||
[CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'Output result into stdout and do not modify files') | ||
[CompletionResult]::new('--preview', 'preview', [CompletionResultType]::ParameterName, 'Output result into stdout and do not modify files') | ||
[CompletionResult]::new('-F', 'F', [CompletionResultType]::ParameterName, 'Treat FIND and REPLACE_WITH args as literal strings') | ||
[CompletionResult]::new('--fixed-strings', 'fixed-strings', [CompletionResultType]::ParameterName, 'Treat FIND and REPLACE_WITH args as literal strings') | ||
[CompletionResult]::new('-r', 'r', [CompletionResultType]::ParameterName, 'Recursively replace files') | ||
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')') | ||
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
_sd() { | ||
local i cur prev opts cmd | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
cmd="" | ||
opts="" | ||
|
||
for i in ${COMP_WORDS[@]} | ||
do | ||
case "${cmd},${i}" in | ||
",$1") | ||
cmd="sd" | ||
;; | ||
*) | ||
;; | ||
esac | ||
done | ||
|
||
case "${cmd}" in | ||
sd) | ||
opts="-p -F -r -n -f -h -V --preview --fixed-strings --flags --help --version <FIND> <REPLACE_WITH> [FILES]..." | ||
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
fi | ||
case "${prev}" in | ||
-n) | ||
COMPREPLY=($(compgen -f "${cur}")) | ||
return 0 | ||
;; | ||
--flags) | ||
COMPREPLY=($(compgen -f "${cur}")) | ||
return 0 | ||
;; | ||
-f) | ||
COMPREPLY=($(compgen -f "${cur}")) | ||
return 0 | ||
;; | ||
*) | ||
COMPREPLY=() | ||
;; | ||
esac | ||
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) | ||
return 0 | ||
;; | ||
esac | ||
} | ||
|
||
complete -F _sd -o bashdefault -o default sd |
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,36 @@ | ||
|
||
use builtin; | ||
use str; | ||
|
||
set edit:completion:arg-completer[sd] = {|@words| | ||
fn spaces {|n| | ||
builtin:repeat $n ' ' | str:join '' | ||
} | ||
fn cand {|text desc| | ||
edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc | ||
} | ||
var command = 'sd' | ||
for word $words[1..-1] { | ||
if (str:has-prefix $word '-') { | ||
break | ||
} | ||
set command = $command';'$word | ||
} | ||
var completions = [ | ||
&'sd'= { | ||
cand -n 'Limit the number of replacements' | ||
cand -f 'Regex flags. May be combined (like `-f mc`).' | ||
cand --flags 'Regex flags. May be combined (like `-f mc`).' | ||
cand -p 'Output result into stdout and do not modify files' | ||
cand --preview 'Output result into stdout and do not modify files' | ||
cand -F 'Treat FIND and REPLACE_WITH args as literal strings' | ||
cand --fixed-strings 'Treat FIND and REPLACE_WITH args as literal strings' | ||
cand -r 'Recursively replace files' | ||
cand -h 'Print help (see more with ''--help'')' | ||
cand --help 'Print help (see more with ''--help'')' | ||
cand -V 'Print version' | ||
cand --version 'Print version' | ||
} | ||
] | ||
$completions[$command] | ||
} |
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,7 @@ | ||
complete -c sd -s n -d 'Limit the number of replacements' -r | ||
complete -c sd -s f -l flags -d 'Regex flags. May be combined (like `-f mc`).' -r | ||
complete -c sd -s p -l preview -d 'Output result into stdout and do not modify files' | ||
complete -c sd -s F -l fixed-strings -d 'Treat FIND and REPLACE_WITH args as literal strings' | ||
complete -c sd -s r -d 'Recursively replace files' | ||
complete -c sd -s h -l help -d 'Print help (see more with \'--help\')' | ||
complete -c sd -s V -l version -d 'Print version' |
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,63 @@ | ||
.TH SD 1 | ||
.SH NAME | ||
sd | ||
.SH SYNOPSIS | ||
\fBsd\fR [FLAGS] find replace_with [FILES] | ||
.SH FLAGS | ||
.TP | ||
\fB\-p\fR, \fB\-\-preview\fR | ||
Emit the replacement to STDOUT | ||
|
||
.TP | ||
\fB\-s\fR, \fB\-\-string\-mode\fR | ||
Treat expressions as non\-regex strings. | ||
|
||
.TP | ||
\fB\-f\fR, \fB\-\-flags\fR | ||
Regex flags. May be combined (like `\-f mc`). | ||
|
||
c \- case\-sensitive | ||
i \- case\-insensitive | ||
m \- multi\-line matching | ||
w \- match full words only | ||
|
||
.SH EXIT STATUS | ||
.TP | ||
\fB0\fR | ||
Successful program execution. | ||
|
||
.TP | ||
\fB1\fR | ||
Unsuccessful program execution. | ||
|
||
.TP | ||
\fB101\fR | ||
The program panicked. | ||
.SH EXAMPLES | ||
.TP | ||
String\-literal mode | ||
\fB$ echo 'lots((([]))) of special chars' | sd \-s '((([])))' ''\fR | ||
.br | ||
lots of special chars | ||
.TP | ||
Regex use. Let's trim some trailing whitespace | ||
\fB$ echo 'lorem ipsum 23 ' | sd '\s+$' ''\fR | ||
.br | ||
lorem ipsum 23 | ||
.TP | ||
Indexed capture groups | ||
\fB$ echo 'cargo +nightly watch' | sd '(\w+)\s+\+(\w+)\s+(\w+)' 'cmd: $1, channel: $2, subcmd: $3'\fR | ||
.br | ||
cmd: cargo, channel: nightly, subcmd: watch | ||
.TP | ||
Named capture groups | ||
\fB$ echo "123.45" | sd '(?P<dollars>\d+)\.(?P<cents>\d+)' '$dollars dollars and $cents cents'\fR | ||
.br | ||
123 dollars and 45 cents | ||
.TP | ||
Find & replace in file | ||
\fB$ sd 'window.fetch' 'fetch' http.js\fR | ||
.TP | ||
Find & replace from STDIN an emit to STDOUT | ||
\fB$ sd 'window.fetch' 'fetch' < http.js\fR | ||
|
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,10 @@ | ||
[package] | ||
name = "xtask" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
clap = "4.3.1" | ||
clap_complete = "4.3.1" | ||
man = "0.3.0" |
Oops, something went wrong.