Skip to content

Commit

Permalink
cli: Make tinygo help experience more consistent with go help tinygo-…
Browse files Browse the repository at this point in the history
…org#3739

- Improve tinygo help command output by streamlining layout and command descriptions
- Reorganize commands and help topics alphabetically, moving info and targets to help topics
- Create a new 'flags' help topic that contains all the flag details
- Introduce gc topic to hold information related to garbage collector options
- Use 'text/tabwriter' for consistent formatting and structuring of the help output

Credit to @m-kru for layout
  • Loading branch information
bjornpagen committed May 22, 2023
1 parent da81784 commit 03c6437
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/CMSIS
Submodule CMSIS updated from 9fe411 to f2cad4
2 changes: 1 addition & 1 deletion lib/avr
Submodule avr updated 142 files
2 changes: 1 addition & 1 deletion lib/binaryen
Submodule binaryen updated 1329 files
2 changes: 1 addition & 1 deletion lib/mingw-w64
Submodule mingw-w64 updated 627 files
2 changes: 1 addition & 1 deletion lib/musl
Submodule musl updated from 7a43f6 to 718f36
2 changes: 1 addition & 1 deletion lib/nrfx
Submodule nrfx updated 628 files
58 changes: 37 additions & 21 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"sync"
"sync/atomic"
"text/tabwriter"
"time"

"github.com/google/shlex"
Expand Down Expand Up @@ -1201,28 +1202,38 @@ func usage(command string) {
switch command {
default:
fmt.Fprintln(os.Stderr, "TinyGo is a Go compiler for small places.")
fmt.Fprintln(os.Stderr, "version:", version)
fmt.Fprintf(os.Stderr, "usage: %s <command> [arguments]\n", os.Args[0])
fmt.Fprintln(os.Stderr, "\ncommands:")
fmt.Fprintln(os.Stderr, " build: compile packages and dependencies")
fmt.Fprintln(os.Stderr, " run: compile and run immediately")
fmt.Fprintln(os.Stderr, " test: test packages")
fmt.Fprintln(os.Stderr, " flash: compile and flash to the device")
fmt.Fprintln(os.Stderr, " gdb: run/flash and immediately enter GDB")
fmt.Fprintln(os.Stderr, " lldb: run/flash and immediately enter LLDB")
fmt.Fprintln(os.Stderr, " monitor: open communication port")
fmt.Fprintln(os.Stderr, " env: list environment variables used during build")
fmt.Fprintln(os.Stderr, " list: run go list using the TinyGo root")
fmt.Fprintln(os.Stderr, " clean: empty cache directory ("+goenv.Get("GOCACHE")+")")
fmt.Fprintln(os.Stderr, " targets: list targets")
fmt.Fprintln(os.Stderr, " info: show info for specified target")
fmt.Fprintln(os.Stderr, " version: show version")
fmt.Fprintln(os.Stderr, " help: print this help text")
fmt.Fprintf(os.Stderr, "version: %s\n\n", version)

if flag.Parsed() {
fmt.Fprintln(os.Stderr, "\nflags:")
flag.PrintDefaults()
}
fmt.Fprintln(os.Stderr, "Usage:\n")
fmt.Fprintln(os.Stderr, "\ttinygo <command> [arguments]\n")
fmt.Fprintln(os.Stderr, "The commands are:\n")

tabw := tabwriter.NewWriter(os.Stderr, 0, 0, 4, ' ', 0)

fmt.Fprintln(tabw, "\tbuild\tcompile packages and dependencies")
fmt.Fprintln(tabw, "\tclean\tempty cache directory (/home/mkru/.cache/tinygo)")
fmt.Fprintln(tabw, "\tenv\tlist environment variables used during build")
fmt.Fprintln(tabw, "\tflash\tcompile and flash to the device")
fmt.Fprintln(tabw, "\tgdb\trun/flash and immediately enter GDB")
fmt.Fprintln(tabw, "\thelp\tprint this help text")
fmt.Fprintln(tabw, "\tlist\trun go list using the TinyGo root")
fmt.Fprintln(tabw, "\tlldb\trun/flash and immediately enter LLDB")
fmt.Fprintln(tabw, "\tmonitor\topen communication port")
fmt.Fprintln(tabw, "\trun\tcompile and run immediately")
fmt.Fprintln(tabw, "\ttest\ttest packages")
fmt.Fprintln(tabw, "\tversion\tshow version")

tabw.Flush()

fmt.Println("\nUse \"tinygo help <command>\" for more information about a command.\n")
fmt.Println("Additional help topics:\n")
fmt.Fprintln(tabw, "\tflags\tgeneral flags")
fmt.Fprintln(tabw, "\tinfo\tshow info for specified target")
fmt.Fprintln(tabw, "\ttargets\tlist targets")

tabw.Flush()

fmt.Fprintln(os.Stderr, "\nUse \"tinygo help <topic>\" for more information about that topic.")

fmt.Fprintln(os.Stderr, "\nfor more details, see https://tinygo.org/docs/reference/usage/")
}
Expand Down Expand Up @@ -1607,6 +1618,11 @@ func main() {
if err != nil {
handleCompilerError(err)
}
case "flag":
if flag.Parsed() {
fmt.Fprintln(os.Stderr, "\nflags:")
flag.PrintDefaults()
}
case "flash", "gdb", "lldb":
pkgName := filepath.ToSlash(flag.Arg(0))
if command == "flash" {
Expand Down

0 comments on commit 03c6437

Please sign in to comment.