commit 632280c428b3b59a4e757bf00746817af687e53c Author: Jason Hall Date: Mon Feb 28 17:07:30 2022 -0500 initial commit diff --git a/.github/workflows/crawl.yaml b/.github/workflows/crawl.yaml new file mode 100644 index 000000000..5fde9e4ed --- /dev/null +++ b/.github/workflows/crawl.yaml @@ -0,0 +1,30 @@ +name: crawl + +on: + workflow_dispatch: + push: + branches: ['main'] + +permissions: + contents: write + +jobs: + crawl: + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.17.x + - uses: google-github-actions/setup-gcloud@v0 + with: + install_components: alpha,beta + + run: crawl.sh + run: | + git config user.name "Automated" + git config user.email "actions@users.noreply.github.com" + git add -A + timestamp=$(date -u) + git commit -m "gcloud: ${timestamp}" || exit 0 + git push + diff --git a/crawl.sh b/crawl.sh new file mode 100755 index 000000000..a96f2ae05 --- /dev/null +++ b/crawl.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +path=$(pwd)/$(printf "%s/" "$@") +mkdir -p $path + +groups=$(gcloud help $@ | go run ./ -print=groups) +commands=$(gcloud help $@ | go run ./ -print=commands) + +gcloud help > help + +for grp in $groups; do + mkdir -p $path/$grp + gcloud help $@ $grp > $path/$grp/help + ./crawl.sh $@ $grp +done + +for cmd in $commands; do + gcloud help $@ $cmd > $path/$cmd +done diff --git a/go.mod b/go.mod new file mode 100644 index 000000000..f1127d830 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/imjasonh/gcloud-help + +go 1.17 + +require github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..51f6dd92c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8= +github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo= diff --git a/main.go b/main.go new file mode 100644 index 000000000..bfcb48512 --- /dev/null +++ b/main.go @@ -0,0 +1,64 @@ +package main + +import ( + "bufio" + "flag" + "fmt" + "log" + "os" + "strings" + + "github.com/acarl005/stripansi" +) + +var print = flag.String("print", "", "what type of thing to print (groups, commands)") + +func main() { + flag.Parse() + + b := bufio.NewScanner(os.Stdin) + var groups, commands []string + var ingroups, incommands bool + for b.Scan() { + txt := stripansi.Strip(b.Text()) + if strings.HasPrefix(txt, " ") { + continue + } + txt = strings.TrimSpace(txt) + if strings.Contains(txt, "GROUPS") { + ingroups = true + incommands = false + continue + } + if strings.Contains(txt, "COMMANDS") { + ingroups = false + incommands = true + continue + } + if strings.Contains(txt, "NOTES") { + break + } + if strings.Contains(txt, " ") { + continue + } + if txt == "" { + continue + } + if ingroups { + groups = append(groups, strings.TrimSpace(txt)) + } + if incommands { + commands = append(commands, strings.TrimSpace(txt)) + } + } + if err := b.Err(); err != nil { + log.Fatal(err) + } + + switch *print { + case "groups": + fmt.Println(strings.Join(groups, " ")) + case "commands": + fmt.Println(strings.Join(commands, " ")) + } +}