https://github.com/hashibuto/artillery
An interactive CLI and command parser for golang
https://github.com/hashibuto/artillery
cli command-line go golang interactive repl shell
Last synced: 9 months ago
JSON representation
An interactive CLI and command parser for golang
- Host: GitHub
- URL: https://github.com/hashibuto/artillery
- Owner: hashibuto
- License: mit
- Archived: true
- Created: 2022-11-26T00:42:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-12-07T21:58:58.000Z (over 1 year ago)
- Last Synced: 2025-03-25T02:43:58.652Z (over 1 year ago)
- Topics: cli, command-line, go, golang, interactive, repl, shell
- Language: Go
- Homepage:
- Size: 1.46 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This repository has been archived, please consider the project's successor: https://github.com/hashibuto/commander
# artillery
An interactive shell/REPL and CLI parser for golang
Artillery can function both as an interactive shell or REPL, as well as a single command CLI parser. In interactive mode, it uses [NilShell](https://github.com/hashibuto/nilshell) for the command line editor, completion, and history.
## A basic interactive shell/REPL
```
import (
"github.com/hashibuto/artillery"
)
processor := artillery.NewProcessor()
cmds := []*artillery.Command{
&artillery.Command{
Name: "hello",
Description: "prints hello to the console",
Arguments: []*artillery.Argument{
{
Name: "name",
Description: "name of the person to which to say hello",
},
},
Options: []*artillery.Option{
{
Name: "shout",
Description: "shout mode",
ShortName: 's',
Type: artillary.Bool
Value: true,
},
},
OnExecute: func(ns artillery.Namespace, processor *artillery.Processor) error {
var args struct {
Name string
Shout bool
}
err := artillery.Reflect(ns, &args)
if err != nil {
return err
}
message := fmt.Sprintf("hello %s!", args.Name)
if args.Shout {
message = strings.ToUpper(message)
}
return nil
},
},
}
for _, c := range cmds {
err := processor.AddCommand(c)
if err != nil {
log.Fatal(err)
}
}
processor.Shell().ReadUntilTerm()
```
## Parse a single CLI command (non-interactive)
```
import (
"github.com/hashibuto/artillery"
"os"
)
helloCmd := &artillery.Command{
Name: "hello",
Description: "prints hello to the console",
Arguments: []*artillery.Argument{
{
Name: "name",
Description: "name of the person to which to say hello",
},
},
Options: []*artillery.Option{
{
Name: "shout",
Description: "shout mode",
ShortName: 's',
Type: artillary.Bool
Value: true,
},
},
OnExecute: func(ns artillery.Namespace, processor *artillery.Processor) error {
var args struct {
Name string
Shout bool
}
err := artillery.Reflect(ns, &args)
if err != nil {
return err
}
message := fmt.Sprintf("hello %s!", args.Name)
if args.Shout {
message = strings.ToUpper(message)
}
return nil
},
}
processor := artillery.NewProcessor()
processor.RemoveBuiltins(false)
err := processor.AddCommands(helloCmd)
if err != nil {
panic(err)
}
err = processor.Process(os.Args[1:])
```
## Special commands / keystrokes
- `clear` clears the terminal
- `!` execs the command ie `!cat /home/user/something` for bash do `!bash -c "cat /home/user/something | grep whatever"`
- `exit` exits
- `` reverse search
- `` move up backwards through the command history
- `` move forwards through the command history
- `` exit
- `` autocomplete
## Example
[Example showcasing most features](https://github.com/hashibuto/artillery/blob/master/example/main.go)