Compare commits
No commits in common. "main" and "1.0" have entirely different histories.
|
@ -18,10 +18,6 @@ tags
|
||||||
|
|
||||||
# You can add/ignore multiple commands at once:
|
# You can add/ignore multiple commands at once:
|
||||||
#bshchk:add-cmd curl wget
|
#bshchk:add-cmd curl wget
|
||||||
|
|
||||||
# To ignore next line:
|
|
||||||
#bshchk:ignore-next-line
|
|
||||||
curl # won't be checked
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
28
ci.sh
28
ci.sh
|
@ -2,23 +2,17 @@
|
||||||
|
|
||||||
rm -f $(find . -type f | grep -E ^\./bshchk.\*)
|
rm -f $(find . -type f | grep -E ^\./bshchk.\*)
|
||||||
|
|
||||||
ver=$(git describe --tags 2> /dev/null)
|
GOOS=linux GOARCH=386 go build -o "bshchk.linux.i386" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
|
GOOS=linux GOARCH=amd64 go build -o "bshchk.linux.amd64" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
|
GOOS=linux GOARCH=arm64 go build -o "bshchk.linux.arm64" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
|
GOOS=linux GOARCH=arm go build -o "bshchk.linux.arm" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
|
|
||||||
GOOS=linux GOARCH=386 go build -o "bshchk.linux.i386" -ldflags "-s -w -X main.version=$ver" . &
|
GOOS=windows GOARCH=386 go build -o "bshchk.windows.i386.exe" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
GOOS=linux GOARCH=amd64 go build -o "bshchk.linux.amd64" -ldflags "-s -w -X main.version=$ver" . &
|
GOOS=windows GOARCH=amd64 go build -o "bshchk.windows.amd64.exe" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
GOOS=linux GOARCH=arm64 go build -o "bshchk.linux.arm64" -ldflags "-s -w -X main.version=$ver" . &
|
GOOS=windows GOARCH=arm64 go build -o "bshchk.windows.arm64.exe" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
GOOS=linux GOARCH=arm go build -o "bshchk.linux.arm" -ldflags "-s -w -X main.version=$ver" . &
|
GOOS=windows GOARCH=arm go build -o "bshchk.windows.arm" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
|
|
||||||
wait
|
GOOS=darwin GOARCH=amd64 go build -o "bshchk.darwin.amd64" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
|
GOOS=darwin GOARCH=arm64 go build -o "bshchk.darwin.arm64" -ldflags "-s -w -X main.version=$VERSION" . &
|
||||||
GOOS=windows GOARCH=386 go build -o "bshchk.windows.i386.exe" -ldflags "-s -w -X main.version=$ver" . &
|
|
||||||
GOOS=windows GOARCH=amd64 go build -o "bshchk.windows.amd64.exe" -ldflags "-s -w -X main.version=$ver" . &
|
|
||||||
GOOS=windows GOARCH=arm64 go build -o "bshchk.windows.arm64.exe" -ldflags "-s -w -X main.version=$ver" . &
|
|
||||||
GOOS=windows GOARCH=arm go build -o "bshchk.windows.arm" -ldflags "-s -w -X main.version=$ver" . &
|
|
||||||
|
|
||||||
wait
|
|
||||||
|
|
||||||
GOOS=darwin GOARCH=amd64 go build -o "bshchk.darwin.amd64" -ldflags "-s -w -X main.version=$ver" . &
|
|
||||||
GOOS=darwin GOARCH=arm64 go build -o "bshchk.darwin.arm64" -ldflags "-s -w -X main.version=$ver" . &
|
|
||||||
|
|
||||||
wait
|
wait
|
||||||
|
|
23
finder.go
23
finder.go
|
@ -6,22 +6,13 @@ import (
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ignored_lines = []uint{}
|
|
||||||
|
|
||||||
func get_ignored_and_deps(code string) ([]string, []string) {
|
func get_ignored_and_deps(code string) ([]string, []string) {
|
||||||
// source: https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html
|
// source: https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html
|
||||||
var ignored []string = []string{"alias", "bind", "builtin", "caller", "command", "declare", "echo", "enable", "let", "local", "logout", "mapfile", "printf", "read", "readarray", "source", "type", "typeset", "ulimit", "unalias"}
|
var ignored []string = []string{"alias", "bind", "builtin", "caller", "command", "declare", "echo", "enable", "let", "local", "logout", "mapfile", "printf", "read", "readarray", "source", "type", "typeset", "ulimit", "unalias"}
|
||||||
var deps []string
|
var deps []string
|
||||||
|
|
||||||
for i, line := range strings.Split(code, "\n") {
|
for _, line := range strings.Split(code, "\n") {
|
||||||
splitted := strings.Split(line, " ")
|
splitted := strings.Split(line, " ")
|
||||||
|
|
||||||
// comments w/ no arguments
|
|
||||||
if splitted[0] == "#bshchk:ignore-next-line" {
|
|
||||||
ignored_lines = append(ignored_lines, uint(i)+1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// comments with arguments
|
|
||||||
if len(splitted) < 2 {
|
if len(splitted) < 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -36,15 +27,6 @@ func get_ignored_and_deps(code string) ([]string, []string) {
|
||||||
return ignored, deps
|
return ignored, deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func is_line_ignored(line uint) bool {
|
|
||||||
for _, ignored := range ignored_lines {
|
|
||||||
if line == ignored {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func find(code string) ([]string, error) {
|
func find(code string) ([]string, error) {
|
||||||
r := strings.NewReader(code)
|
r := strings.NewReader(code)
|
||||||
f, err := syntax.NewParser().Parse(r, "")
|
f, err := syntax.NewParser().Parse(r, "")
|
||||||
|
@ -68,9 +50,6 @@ func find(code string) ([]string, error) {
|
||||||
syntax.Walk(f, func(node syntax.Node) bool {
|
syntax.Walk(f, func(node syntax.Node) bool {
|
||||||
switch x := node.(type) {
|
switch x := node.(type) {
|
||||||
case *syntax.CallExpr:
|
case *syntax.CallExpr:
|
||||||
if is_line_ignored(node.Pos().Line() - 1) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
for i := range x.Args {
|
for i := range x.Args {
|
||||||
for _, part := range x.Args[i].Parts {
|
for _, part := range x.Args[i].Parts {
|
||||||
switch xx := part.(type) {
|
switch xx := part.(type) {
|
||||||
|
|
40
main.go
40
main.go
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -16,18 +15,10 @@ var args struct {
|
||||||
File string `arg:"positional" help:"if not specified, will read from stdin" default:""`
|
File string `arg:"positional" help:"if not specified, will read from stdin" default:""`
|
||||||
Outfile string `arg:"positional" help:"if not specified, will emit to stdout" default:""`
|
Outfile string `arg:"positional" help:"if not specified, will emit to stdout" default:""`
|
||||||
Version bool `arg:"-v" help:"print version and exit"`
|
Version bool `arg:"-v" help:"print version and exit"`
|
||||||
YieldDepsOnly bool `arg:"--yield-deps-only" help:"print dependencies as a JSON array and exit" default:"false"`
|
YieldDepsOnly bool `arg:"--yield-deps-only" help:"print dependencies as a JSON array and exit" default:false`
|
||||||
ExposeDeps bool `arg:"--expose-deps" help:"expose dependencies to program" default:"false"`
|
ExposeDeps bool `arg:"--expose-deps" help:"expose dependencies to program" default:false`
|
||||||
DepsVarName string `arg:"--deps-var-name" help:"override deps variable name" default:"deps"`
|
DepsVarName string `arg:"--deps-var-name" help:"override deps variable name" default:"deps"`
|
||||||
IgnoreShebang bool `arg:"--ignore-shebang" help:"ignore shebang requirement" default:"false"`
|
IgnoreShebang bool `arg:"--ignore-shebang" help:"ignore shebang requirement" default:false`
|
||||||
}
|
|
||||||
|
|
||||||
func emit(code string) {
|
|
||||||
if args.Outfile == "" {
|
|
||||||
fmt.Printf("%s", code)
|
|
||||||
} else {
|
|
||||||
os.WriteFile(args.Outfile, []byte(code), os.FileMode(0o755))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -64,24 +55,6 @@ func main() {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.YieldDepsOnly {
|
|
||||||
marshaled, err := json.Marshal(found)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if string(marshaled) == "null" {
|
|
||||||
emit("[]")
|
|
||||||
} else {
|
|
||||||
emit(string(marshaled))
|
|
||||||
}
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(found) == 0 {
|
|
||||||
emit(code)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
codelines := strings.Split(code, "\n")
|
codelines := strings.Split(code, "\n")
|
||||||
|
|
||||||
if len(codelines) < 2 {
|
if len(codelines) < 2 {
|
||||||
|
@ -97,5 +70,10 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
gen := shebang + "\n\n" + gencode(found) + "\n\n" + strings.Join(codelines[1:], "\n")
|
gen := shebang + "\n\n" + gencode(found) + "\n\n" + strings.Join(codelines[1:], "\n")
|
||||||
emit(gen)
|
|
||||||
|
if args.Outfile == "" {
|
||||||
|
fmt.Printf("%s", gen)
|
||||||
|
} else {
|
||||||
|
os.WriteFile(args.Outfile, []byte(gen), os.FileMode(0o755))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
5
rdc.sh
5
rdc.sh
|
@ -17,9 +17,8 @@ if (( ${#non_ok[@]} != 0 )); then
|
||||||
>&2 echo " From which, these are missing:"
|
>&2 echo " From which, these are missing:"
|
||||||
>&2 echo " > $non_ok"
|
>&2 echo " > $non_ok"
|
||||||
>&2 echo "Make sure that those are installed and are present in \$PATH."
|
>&2 echo "Make sure that those are installed and are present in \$PATH."
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset non_ok{{if .UnsetDeps}}
|
unset non_ok{{if .UnsetDeps}}
|
||||||
unset {{.DepsVar}}{{end}}
|
unset {{.DepsVar}}
|
||||||
# Dependencies are OK at this point
|
{{end}}# Dependencies are OK at this point
|
|
@ -18,10 +18,6 @@ type Template struct {
|
||||||
|
|
||||||
func gencode(deps []string) string {
|
func gencode(deps []string) string {
|
||||||
|
|
||||||
if len(deps) == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
rdc := Template{args.DepsVarName, "'" + strings.Join(deps, "' '") + "'", !args.ExposeDeps}
|
rdc := Template{args.DepsVarName, "'" + strings.Join(deps, "' '") + "'", !args.ExposeDeps}
|
||||||
tmpl, err := template.New("").Parse(bin)
|
tmpl, err := template.New("").Parse(bin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue