diff --git a/commands/cargo.go b/commands/dev/cargo.go similarity index 98% rename from commands/cargo.go rename to commands/dev/cargo.go index f5638ff..cbd1ccc 100644 --- a/commands/cargo.go +++ b/commands/dev/cargo.go @@ -1,4 +1,4 @@ -package commands +package dev import ( "github.com/versenilvis/iris/commands/core" diff --git a/commands/docker.go b/commands/dev/docker.go similarity index 99% rename from commands/docker.go rename to commands/dev/docker.go index c679f1d..b1cf7ea 100644 --- a/commands/docker.go +++ b/commands/dev/docker.go @@ -1,4 +1,4 @@ -package commands +package dev import ( "github.com/versenilvis/iris/commands/core" diff --git a/commands/git.go b/commands/dev/git.go similarity index 99% rename from commands/git.go rename to commands/dev/git.go index c1fa682..35dffc3 100644 --- a/commands/git.go +++ b/commands/dev/git.go @@ -1,4 +1,4 @@ -package commands +package dev import ( "github.com/versenilvis/iris/commands/core" @@ -41,6 +41,7 @@ func init() { { Name: "add", Description: "stage changes", + Generator: core.FileGenerator(), Options: []core.Option{ {Name: "-A", Description: "add all files"}, {Name: "-p", Description: "interactive patch"}, diff --git a/commands/dev/go.go b/commands/dev/go.go new file mode 100644 index 0000000..f9d9929 --- /dev/null +++ b/commands/dev/go.go @@ -0,0 +1,194 @@ +package dev + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + globalBuildOptions := []core.Option{ + {Name: "-v", Description: "print package names"}, + {Name: "-n", Description: "print commands but do not run"}, + {Name: "-x", Description: "print commands as they run"}, + {Name: "-race", Description: "enable data race detection"}, + {Name: "-tags", Description: "comma-separated build tags"}, + {Name: "-ldflags", Description: "arguments to pass to linker"}, + {Name: "-gcflags", Description: "arguments to pass to compiler"}, + {Name: "-asmflags", Description: "arguments to pass to assembler"}, + {Name: "-compiler", Description: "name of compiler to use (gccgo or gc)"}, + {Name: "-work", Description: "print temporary work directory"}, + {Name: "-mod", Description: "module download mode (readonly, vendor, or mod)"}, + {Name: "-trimpath", Description: "remove file system paths from executable"}, + {Name: "-p", Description: "number of programs to run in parallel"}, + {Name: "-a", Description: "force rebuilding of up-to-date packages"}, + } + + buildModeSubcommands := []core.Subcommand{ + {Name: "archive", Description: "build non-main packages into .a files"}, + {Name: "c-archive", Description: "build main package into C archive"}, + {Name: "c-shared", Description: "build main package into C shared library"}, + {Name: "exe", Description: "build main packages into executables"}, + {Name: "pie", Description: "build position independent executables"}, + {Name: "plugin", Description: "build main packages into Go plugin"}, + {Name: "shared", Description: "combine packages into single shared library"}, + } + + core.Register(&core.Spec{ + Name: "go", + Description: "tool for managing Go source code", + Subcommands: []core.Subcommand{ + { + Name: "build", + Description: "compile packages and dependencies", + Generator: core.FileGenerator(".go"), + Options: append(globalBuildOptions, + core.Option{Name: ".", Description: "current package"}, + core.Option{Name: "./...", Description: "all packages"}, + core.Option{Name: "-o", Description: "output file or directory"}, + core.Option{Name: "-i", Description: "install dependency packages"}, + core.Option{Name: "-buildmode", Description: "build mode to use"}, + ), + Subcommands: buildModeSubcommands, + }, + { + Name: "run", + Description: "compile and run Go program", + Generator: core.FileGenerator(".go"), + Options: append(globalBuildOptions, + core.Option{Name: ".", Description: "current package"}, + core.Option{Name: "-exec", Description: "invoke binary using xprog"}, + ), + }, + { + Name: "test", + Description: "test packages", + Generator: core.FileGenerator(".go"), + Options: append(globalBuildOptions, + core.Option{Name: ".", Description: "current package"}, + core.Option{Name: "./...", Description: "all packages"}, + core.Option{Name: "-c", Description: "compile test binary but do not run"}, + core.Option{Name: "-i", Description: "install test dependencies"}, + core.Option{Name: "-json", Description: "convert output to JSON"}, + core.Option{Name: "-bench", Description: "run benchmarks"}, + core.Option{Name: "-run", Description: "run specific test regex"}, + core.Option{Name: "-cover", Description: "enable coverage report"}, + ), + }, + { + Name: "mod", + Description: "module maintenance", + Subcommands: []core.Subcommand{ + {Name: "init", Description: "initialize new module"}, + {Name: "tidy", Description: "add missing and remove unused modules"}, + {Name: "download", Description: "download modules to local cache"}, + {Name: "vendor", Description: "make vendored copy of dependencies"}, + {Name: "edit", Description: "edit go.mod from tools or scripts"}, + {Name: "graph", Description: "print module requirement graph"}, + {Name: "verify", Description: "verify dependencies have expected content"}, + {Name: "why", Description: "explain why packages or modules are needed"}, + }, + }, + { + Name: "get", + Description: "add dependencies to current module and install them", + Options: append(globalBuildOptions, + core.Option{Name: "-u", Description: "update to newer minor/patch releases"}, + core.Option{Name: "-t", Description: "download modules needed for tests"}, + core.Option{Name: "-d", Description: "only download, do not install"}, + ), + }, + { + Name: "install", + Description: "compile and install packages and dependencies", + Options: globalBuildOptions, + }, + { + Name: "list", + Description: "list packages or modules", + Options: append(globalBuildOptions, + core.Option{Name: "-m", Description: "list modules instead of packages"}, + core.Option{Name: "-u", Description: "add upgrade information"}, + core.Option{Name: "-json", Description: "print in JSON format"}, + core.Option{Name: "-f", Description: "specify alternate format"}, + ), + }, + { + Name: "fmt", + Description: "gofmt (reformat) package sources", + Options: []core.Option{ + {Name: "-n", Description: "print commands that would be executed"}, + {Name: "-x", Description: "print commands as they are executed"}, + }, + }, + { + Name: "vet", + Description: "report likely mistakes in packages", + Options: globalBuildOptions, + }, + { + Name: "env", + Description: "print Go environment information", + Options: []core.Option{ + {Name: "-json", Description: "print environment in JSON format"}, + {Name: "-u", Description: "unset named environment variables"}, + {Name: "-w", Description: "change default settings of environment variables"}, + }, + }, + { + Name: "version", + Description: "print Go version", + Options: []core.Option{ + {Name: "-m", Description: "print embedded module version info"}, + {Name: "-v", Description: "report unrecognized files"}, + }, + }, + { + Name: "clean", + Description: "remove object files and cached files", + Options: append(globalBuildOptions, + core.Option{Name: "-i", Description: "remove installed archive or binary"}, + core.Option{Name: "-cache", Description: "remove entire go build cache"}, + core.Option{Name: "-modcache", Description: "remove entire module cache"}, + ), + }, + { + Name: "tool", + Description: "run specified go tool", + Options: []core.Option{ + {Name: "-n", Description: "print command but do not execute"}, + }, + }, + { + Name: "work", + Description: "workspace maintenance", + Subcommands: []core.Subcommand{ + {Name: "init", Description: "initialize workspace file"}, + {Name: "edit", Description: "edit go.work from tools or scripts"}, + {Name: "sync", Description: "sync workspace build list to modules"}, + {Name: "use", Description: "add modules to workspace file"}, + }, + }, + { + Name: "doc", + Description: "show documentation for package or symbol", + Options: []core.Option{ + {Name: "-all", Description: "show all documentation"}, + {Name: "-cmd", Description: "treat package main like regular package"}, + {Name: "-src", Description: "show full source code"}, + }, + }, + { + Name: "bug", + Description: "start a bug report", + }, + { + Name: "fix", + Description: "update packages to use new APIs", + }, + { + Name: "generate", + Description: "generate Go files by processing source", + Options: globalBuildOptions, + }, + }, + }) +} diff --git a/commands/kubectl.go b/commands/dev/kubectl.go similarity index 98% rename from commands/kubectl.go rename to commands/dev/kubectl.go index 5b9364f..9f38196 100644 --- a/commands/kubectl.go +++ b/commands/dev/kubectl.go @@ -1,4 +1,4 @@ -package commands +package dev import ( "github.com/versenilvis/iris/commands/core" diff --git a/commands/npm.go b/commands/dev/npm.go similarity index 98% rename from commands/npm.go rename to commands/dev/npm.go index a93fa8d..db603bd 100644 --- a/commands/npm.go +++ b/commands/dev/npm.go @@ -1,4 +1,4 @@ -package commands +package dev import ( "github.com/versenilvis/iris/commands/core" diff --git a/commands/pip.go b/commands/dev/pip.go similarity index 96% rename from commands/pip.go rename to commands/dev/pip.go index d005e92..b9c7e74 100644 --- a/commands/pip.go +++ b/commands/dev/pip.go @@ -1,4 +1,4 @@ -package commands +package dev import ( "github.com/versenilvis/iris/commands/core" diff --git a/commands/fs/cd.go b/commands/fs/cd.go new file mode 100644 index 0000000..333f9ff --- /dev/null +++ b/commands/fs/cd.go @@ -0,0 +1,13 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "cd", + Description: "change directory", + Generator: core.FileGenerator("/"), // Directory only + }) +} diff --git a/commands/fs/chmod.go b/commands/fs/chmod.go new file mode 100644 index 0000000..6258c1e --- /dev/null +++ b/commands/fs/chmod.go @@ -0,0 +1,16 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "chmod", + Description: "change file permissions", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-R", Description: "recursive"}, + }, + }) +} diff --git a/commands/fs/chown.go b/commands/fs/chown.go new file mode 100644 index 0000000..b64fef2 --- /dev/null +++ b/commands/fs/chown.go @@ -0,0 +1,16 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "chown", + Description: "change file owner", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-R", Description: "recursive"}, + }, + }) +} diff --git a/commands/fs/cp.go b/commands/fs/cp.go new file mode 100644 index 0000000..4ed47b0 --- /dev/null +++ b/commands/fs/cp.go @@ -0,0 +1,21 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "cp", + Description: "copy files and directories", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-r", Description: "recursive"}, + {Name: "-a", Description: "archive mode"}, + {Name: "-v", Description: "verbose"}, + {Name: "-i", Description: "interactive"}, + {Name: "-u", Description: "update (copy only if newer)"}, + {Name: "-p", Description: "preserve attributes"}, + }, + }) +} diff --git a/commands/fs/ln.go b/commands/fs/ln.go new file mode 100644 index 0000000..9d6d2c1 --- /dev/null +++ b/commands/fs/ln.go @@ -0,0 +1,17 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "ln", + Description: "create links", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-s", Description: "symbolic link"}, + {Name: "-f", Description: "force"}, + }, + }) +} diff --git a/commands/fs/ls.go b/commands/fs/ls.go new file mode 100644 index 0000000..557b946 --- /dev/null +++ b/commands/fs/ls.go @@ -0,0 +1,20 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "ls", + Description: "list directory contents", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-a", Description: "all files"}, + {Name: "-l", Description: "long format"}, + {Name: "-h", Description: "human readable"}, + {Name: "-R", Description: "recursive"}, + {Name: "-t", Description: "sort by time"}, + }, + }) +} diff --git a/commands/fs/mkdir.go b/commands/fs/mkdir.go new file mode 100644 index 0000000..a187a0e --- /dev/null +++ b/commands/fs/mkdir.go @@ -0,0 +1,16 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "mkdir", + Description: "make directories", + Options: []core.Option{ + {Name: "-p", Description: "create parent dirs"}, + {Name: "-v", Description: "verbose"}, + }, + }) +} diff --git a/commands/fs/mv.go b/commands/fs/mv.go new file mode 100644 index 0000000..44504f0 --- /dev/null +++ b/commands/fs/mv.go @@ -0,0 +1,19 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "mv", + Description: "move (rename) files", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-i", Description: "interactive"}, + {Name: "-f", Description: "force (overwrite)"}, + {Name: "-n", Description: "no clobber (don't overwrite)"}, + {Name: "-v", Description: "verbose"}, + }, + }) +} diff --git a/commands/fs/rm.go b/commands/fs/rm.go new file mode 100644 index 0000000..f80ed8a --- /dev/null +++ b/commands/fs/rm.go @@ -0,0 +1,20 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "rm", + Description: "remove files or directories", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-r", Description: "recursive"}, + {Name: "-f", Description: "force"}, + {Name: "-i", Description: "interactive"}, + {Name: "-v", Description: "verbose"}, + {Name: "-d", Description: "remove empty directories"}, + }, + }) +} diff --git a/commands/fs/touch.go b/commands/fs/touch.go new file mode 100644 index 0000000..66002d9 --- /dev/null +++ b/commands/fs/touch.go @@ -0,0 +1,13 @@ +package fs + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "touch", + Description: "create or update file timestamp", + Generator: core.FileGenerator(), + }) +} diff --git a/commands/go.go b/commands/go.go deleted file mode 100644 index 0075eda..0000000 --- a/commands/go.go +++ /dev/null @@ -1,99 +0,0 @@ -package commands - -import ( - "github.com/versenilvis/iris/commands/core" -) - -func init() { - core.Register(&core.Spec{ - Name: "go", - Description: "go toolchain", - Subcommands: []core.Subcommand{ - { - Name: "build", - Description: "compile packages", - Options: []core.Option{ - {Name: "-o", Description: "output file"}, - {Name: "-v", Description: "verbose"}, - {Name: "-race", Description: "enable race detector"}, - {Name: "-ldflags", Description: "linker flags"}, - }, - }, - { - Name: "run", - Description: "compile and run", - Options: []core.Option{ - {Name: "-race", Description: "enable race detector"}, - }, - }, - { - Name: "test", - Description: "run tests", - Options: []core.Option{ - {Name: "-v", Description: "verbose output"}, - {Name: "-run", Description: "run specific test"}, - {Name: "-bench", Description: "run benchmarks"}, - {Name: "-cover", Description: "coverage report"}, - {Name: "-count", Description: "run count times"}, - {Name: "-race", Description: "enable race detector"}, - }, - }, - { - Name: "mod", - Description: "module maintenance", - Subcommands: []core.Subcommand{ - {Name: "init", Description: "initialize module"}, - {Name: "tidy", Description: "clean up modules"}, - {Name: "download", Description: "download modules"}, - {Name: "vendor", Description: "make vendor copy"}, - {Name: "edit", Description: "edit go.mod"}, - {Name: "graph", Description: "print module graph"}, - {Name: "verify", Description: "verify dependencies"}, - }, - }, - { - Name: "get", - Description: "add dependency", - Options: []core.Option{ - {Name: "-u", Description: "update module"}, - }, - }, - { - Name: "fmt", - Description: "format source", - }, - { - Name: "vet", - Description: "examine code", - }, - { - Name: "install", - Description: "compile and install", - }, - { - Name: "generate", - Description: "run go generate", - }, - { - Name: "clean", - Description: "remove object files", - Options: []core.Option{ - {Name: "-cache", Description: "clean build cache"}, - {Name: "-testcache", Description: "clean test cache"}, - }, - }, - { - Name: "env", - Description: "print go environment", - }, - { - Name: "doc", - Description: "show documentation", - }, - { - Name: "tool", - Description: "run go tool", - }, - }, - }) -} diff --git a/commands/info/du.go b/commands/info/du.go new file mode 100644 index 0000000..0e7d24e --- /dev/null +++ b/commands/info/du.go @@ -0,0 +1,18 @@ +package info + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "du", + Description: "estimate file space usage", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-h", Description: "human readable"}, + {Name: "-s", Description: "summarize"}, + {Name: "-a", Description: "all files"}, + }, + }) +} diff --git a/commands/info/file.go b/commands/info/file.go new file mode 100644 index 0000000..7e7a9b8 --- /dev/null +++ b/commands/info/file.go @@ -0,0 +1,13 @@ +package info + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "file", + Description: "determine file type", + Generator: core.FileGenerator(), + }) +} diff --git a/commands/info/stat.go b/commands/info/stat.go new file mode 100644 index 0000000..5e8e025 --- /dev/null +++ b/commands/info/stat.go @@ -0,0 +1,13 @@ +package info + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "stat", + Description: "display file status", + Generator: core.FileGenerator(), + }) +} diff --git a/commands/info/wc.go b/commands/info/wc.go new file mode 100644 index 0000000..8e66b9c --- /dev/null +++ b/commands/info/wc.go @@ -0,0 +1,18 @@ +package info + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "wc", + Description: "word, line, character count", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-l", Description: "count lines"}, + {Name: "-w", Description: "count words"}, + {Name: "-c", Description: "count bytes"}, + }, + }) +} diff --git a/commands/justfile.go b/commands/runner/justfile.go similarity index 94% rename from commands/justfile.go rename to commands/runner/justfile.go index 87c111c..79f6472 100644 --- a/commands/justfile.go +++ b/commands/runner/justfile.go @@ -1,4 +1,4 @@ -package commands +package runner import ( "bufio" @@ -13,7 +13,7 @@ func init() { core.Register(&core.Spec{ Name: "just", Description: "command runner", - Generator: func(tokens []string, prefix string) []core.Suggestion { + Generator: func(tokens []string, prefix string, partial string) []core.Suggestion { file, err := os.Open("justfile") if err != nil { // try uppercase diff --git a/commands/makefile.go b/commands/runner/makefile.go similarity index 92% rename from commands/makefile.go rename to commands/runner/makefile.go index b4f32f0..bb99d2a 100644 --- a/commands/makefile.go +++ b/commands/runner/makefile.go @@ -1,4 +1,4 @@ -package commands +package runner import ( "bufio" @@ -12,7 +12,7 @@ func init() { core.Register(&core.Spec{ Name: "make", Description: "build automation", - Generator: func(tokens []string, prefix string) []core.Suggestion { + Generator: func(tokens []string, prefix string, partial string) []core.Suggestion { // Read the Makefile file, err := os.Open("Makefile") if err != nil { diff --git a/commands/search/find.go b/commands/search/find.go new file mode 100644 index 0000000..fe858c1 --- /dev/null +++ b/commands/search/find.go @@ -0,0 +1,19 @@ +package search + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "find", + Description: "search for files", + Generator: core.FileGenerator("/"), + Options: []core.Option{ + {Name: "-name", Description: "match by name"}, + {Name: "-type", Description: "match by type (f/d)"}, + {Name: "-size", Description: "match by size"}, + {Name: "-mtime", Description: "match by modified time"}, + }, + }) +} diff --git a/commands/search/grep.go b/commands/search/grep.go new file mode 100644 index 0000000..9161f50 --- /dev/null +++ b/commands/search/grep.go @@ -0,0 +1,20 @@ +package search + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "grep", + Description: "search text in files", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-r", Description: "recursive"}, + {Name: "-i", Description: "ignore case"}, + {Name: "-n", Description: "show line numbers"}, + {Name: "-v", Description: "invert match"}, + {Name: "-l", Description: "show filenames only"}, + }, + }) +} diff --git a/commands/view/cat.go b/commands/view/cat.go new file mode 100644 index 0000000..90d57ac --- /dev/null +++ b/commands/view/cat.go @@ -0,0 +1,17 @@ +package view + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "cat", + Description: "concatenate and print", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-n", Description: "number lines"}, + {Name: "-b", Description: "number non-blank"}, + }, + }) +} diff --git a/commands/view/head.go b/commands/view/head.go new file mode 100644 index 0000000..7dadb32 --- /dev/null +++ b/commands/view/head.go @@ -0,0 +1,16 @@ +package view + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "head", + Description: "output first lines of file", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-n", Description: "number of lines"}, + }, + }) +} diff --git a/commands/view/less.go b/commands/view/less.go new file mode 100644 index 0000000..9a7ffb4 --- /dev/null +++ b/commands/view/less.go @@ -0,0 +1,13 @@ +package view + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "less", + Description: "view file contents (scrollable)", + Generator: core.FileGenerator(), + }) +} diff --git a/commands/view/tail.go b/commands/view/tail.go new file mode 100644 index 0000000..34a63f9 --- /dev/null +++ b/commands/view/tail.go @@ -0,0 +1,17 @@ +package view + +import ( + "github.com/versenilvis/iris/commands/core" +) + +func init() { + core.Register(&core.Spec{ + Name: "tail", + Description: "output last lines of file", + Generator: core.FileGenerator(), + Options: []core.Option{ + {Name: "-n", Description: "number of lines"}, + {Name: "-f", Description: "follow (live updates)"}, + }, + }) +} diff --git a/root/root.go b/root/root.go index 8fcad23..d731bd2 100644 --- a/root/root.go +++ b/root/root.go @@ -14,7 +14,12 @@ import ( "github.com/creack/pty" "github.com/spf13/cobra" - _ "github.com/versenilvis/iris/commands" + _ "github.com/versenilvis/iris/commands/dev" + _ "github.com/versenilvis/iris/commands/fs" + _ "github.com/versenilvis/iris/commands/info" + _ "github.com/versenilvis/iris/commands/runner" + _ "github.com/versenilvis/iris/commands/search" + _ "github.com/versenilvis/iris/commands/view" "github.com/versenilvis/iris/commands/core" "github.com/versenilvis/iris/integration" "golang.org/x/term"