Climax is an alternative CLI with the human face

Climax

Climax is an alternative CLI that looks like Go command

GoDoc Travis

Climax is a handy alternative CLI (command-line interface) for Go apps. It looks pretty much exactly like the output of the default go command and incorporates some fancy features from it. For instance, Climax does support so-called topics (some sort of Wiki entries for CLI). You can define some annotated use cases of some command that would get displayed in the help section of corresponding command also.

Why creating another CLI?

I didn't like existing solutions (e.g. codegangsta/cli | spf13/cobra) either for bloated codebase (I dislike the huge complex libraries) or poor output style / API. This project is just an another view on the subject, it has slightly different API than, let's say, Cobra; I find it much more convenient.


A sample application output, Climax produces:

Camus is a modern content writing suite.

Usage:

	camus command [arguments]

The commands are:

	init        starts a new project
	new         creates flavored book parts

Use "camus help [command]" for more information about a command.

Additional help topics:

	writing     markdown language cheatsheet
	metadata    intro to yaml-based metadata
	realtime    effective real-time writing

Use "camus help [topic]" for more information about a topic.

Here is an example of a trivial CLI application that does nothing, but provides a single string split-like functionality:

demo := climax.New("demo")
demo.Brief = "Demo is a funky demonstation of Climax capabilities."
demo.Version = "stable"

joinCmd := climax.Command{
	Name:  "join",
	Brief: "merges the strings given",
	Usage: `[-s=] "a few" distinct strings`,
	Help:  `Lorem ipsum dolor sit amet amet sit todor...`,

	Flags: []climax.Flag{
		{
			Name:     "separator",
			Short:    "s",
			Usage:    `--separator="."`,
			Help:     `Put some separating string between all the strings given.`,
			Variable: true,
		},
	},

	Examples: []climax.Example{
		{
			Usecase:     `-s . "google" "com"`,
			Description: `Results in "google.com"`,
		},
	},

	Handle: func(ctx climax.Context) int {
		var separator string
		if sep, ok := ctx.Get("separator"); ok {
			separator = sep
		}

		fmt.Println(strings.Join(ctx.Args, separator))

		return 0
	},
}

demo.AddCommand(joinCmd)
demo.Run()

Have fun!

Owner
Ian P Badtrousers
i have had many alohols
Ian P Badtrousers
Comments
  • Introduce (optional) categories to group subcommands

    Introduce (optional) categories to group subcommands

    For some larger programs it's sometimes useful to group commands into categories. This patch should not alter normal output, but when filling out Command.Category, it will be grouped accordingly.

    Here's an example from ipfs:

    
        ipfs - global p2p merkle-dag filesystem
    
        ipfs [<flags>] <command> [<arg>] ...
    
        BASIC COMMANDS
    
            init          Initialize ipfs local configuration
            add <path>    Add an object to ipfs
            cat <ref>     Show ipfs object data
            get <ref>     Download ipfs objects
            ls <ref>      List links from an object
            refs <ref>    List hashes of links from an object
    
        DATA STRUCTURE COMMANDS
    
            block         Interact with raw blocks in the datastore
            object        Interact with raw dag nodes
            file          Interact with Unix filesystem objects
    
        ADVANCED COMMANDS
    
            daemon        Start a long-running daemon process
            mount         Mount an ipfs read-only mountpoint
            resolve       Resolve any type of name
            name          Publish or resolve IPNS names
            dns           Resolve DNS links
            pin           Pin objects to local storage
            repo gc       Garbage collect unpinned objects
    
        NETWORK COMMANDS
    
            id            Show info about ipfs peers
            bootstrap     Add or remove bootstrap peers
            swarm         Manage connections to the p2p network
            dht           Query the dht for values or peers
            ping          Measure the latency of a connection
            diag          Print diagnostics
    
        TOOL COMMANDS
    
            config        Manage configuration
            version       Show ipfs version information
            update        Download and apply go-ipfs updates
            commands      List all available commands
    
  • If I try to use a flag in CLI that is not defined, gets a panic

    If I try to use a flag in CLI that is not defined, gets a panic

    If try tu run a small minimal app with climax, that doesn't have 't' flag defined, I get a panic:

     # ./stellar-stacy serve -t=3
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x40 pc=0x4814b6]
    
    goroutine 1 [running]:
    github.com/tucnak/climax.parseContext(0xc8200a0410, 0x1, 0x1, 0xc82007e260, 0x1, 0x1, 0x1, 0x0, 0x0)
        /home/foo/go/src/github.com/tucnak/climax/context.go:97 +0x496
    github.com/tucnak/climax.Application.Run(0x78c890, 0x6, 0x7c1b80, 0x10, 0x821350, 0x13, 0xc8200ba180, 0x1, 0x1, 0x0, ...)
        /home/foo/go/src/github.com/tucnak/climax/application.go:117 +0xa19
    main.main()
        /home/foo/go/src/myserver/myroot/stellar-stacy/main.go:21 +0x173
    

    When launching it with a flag that exists, it works fine. The climax.Command structure I used is the one defined on the main github page.

  • Do you support subcommands?

    Do you support subcommands?

    I thought that groups would be subcommands, but it seems they are only for grouping them on the help page. Does climax currently support subcommands? If so, how?

  • Iterators?

    Iterators?

    I am using this library in my application at https://github.com/parallelcointeam/pod - because it seems to be the most friendly and accessible CLI flags library that exists for Go. However, my application needs some 40-50 separate parameters in most instances of the use of climax and I used a function wrapper to condense the declarations, but the ctx.Is and ctx.Get functions chew up a whole if block per parameter.

    I am looking at it, and for the reason that the function that reads off the values from the command line to overlay the configuration struct for the subcommands, I looked closer at the source and noted that the variable and non-variable types have exported names and thus can be iterated.

    Of course it is not (that) difficult to write this, but I'm just posting this issue to suggest that it could have an iterator built into it if one defined a map type that contains the pointers to the variables, in the case of variables, and for the nonvariable case, could produce an array containing the handlers associated with the nonvariable flags to enable order sensitivity to the triggers so in the case of a subcommand that terminates, that it can do this from one map literal declaration and the iterator command, and automatically executes it.

    I am immediately in the process of refactoring my code's use of this by using an iterator on these maps, I would think that probably the function could be quickly modified to become generic, using a map[string]interface{}, enable the automatic determination of intended variable type, assignment and resolution of the interface to direct explicit type. I am using JSON as the configuration file format also, so I can constrain the types to match JSON in as much as objects go to maps and arrays to slices, then bool, int, float and string.

    If there is interest in having a PR for adding this iterator, let me know, and I probably can create an additional source file to go with the library that implements this.

  • Lightweight command syntax

    Lightweight command syntax

    We need a super lightweight syntax of creating simple flag-less commands. Something like this would be great:

    app := climax.New("appname")
    
    app.Comm("command", "i am command", func (ctx climax.Context) {
        return 0;
    });
    
Related tags
Clirunner - Package clirunner runs a legacy shell-style CLI as if a human were running it.

clirunner Package clirunner runs a legacy shell-style command-line interpreter (CLI) as if a human were running it. A shell-style CLI offers a prompt

Jan 4, 2022
lsp is like ls command but more human-friendly
lsp is like ls command but more human-friendly

lsp: list files in a mildly human-frendlier manner lsp lists files, like ls command, but it does not attempt to meet that archaic POSIX specification,

Dec 12, 2022
A command line tool for quickly converting Unix timestamps to human readable form.

stamp A command line tool to quickly format a Unix timestamp in a human-readable form. Installation Go is required to build this software. To just bui

Oct 30, 2021
Command line tool for time tracking in a human-readable file format.

klog klog is a plain-text file format and a command line tool for time tracking. ?? Documentation – Learn how to use klog ?? Download – Get the latest

Jan 4, 2023
A command line utility that automagically replaces UNIX timestamps with human interpretable timestamps.

Unfy unfy is a command line utility that automagically identifies and translated UNIX timestamps (since epoch) to human readable timestamps. Example B

Oct 22, 2022
A fast and powerful alternative to grep

sift A fast and powerful open source alternative to grep. Features sift has a slightly different focus than most other grep alternatives. Code search,

Jan 3, 2023
giter8 alternative in Go

go-giter8 go-giter8 implements a simple library capable of handling giter8 templates. Using as library Add to go.mod module github.com/yourusername/yo

Sep 5, 2022
An alternative syntax to generate YAML (or JSON) from commandline

yo An alternative syntax to generate YAML (or JSON) from commandline. The ultimate commanline YAML (or JSON) generator! ... I'm kidding of course! but

Jul 30, 2022
🐘 Cross-platform, neofetch alternative for fetching system info.
 🐘 Cross-platform, neofetch alternative for fetching system info.

elefetch ?? Cross-platform, neofetch alternative for fetching system info. Installation go get: go get -u github.com/burntcarrot/elefetch Binaries Bin

Jan 23, 2022
archy is an static binary to determine current kernel and machine architecture, with backwards compatible flags to uname, and offers alternative output format of Go runtime (i.e. GOOS, GOARCH).

archy archy is an simple binary to determine current kernel and machine architecture, which wraps uname and alternatively can read from Go runtime std

Mar 18, 2022
Elegant CLI wrapper for kubeseal CLI

Overview This is a wrapper CLI ofkubeseal CLI, specifically the raw mode. If you just need to encrypt your secret on RAW mode, this CLI will be the ea

Jan 8, 2022
CLI to run a docker image with R. CLI built using cobra library in go.
CLI  to run a docker image with R. CLI built using cobra library in go.

BlueBeak Installation Guide Task 1: Building the CLI The directory structure looks like Fastest process: 1)cd into bbtools 2)cd into bbtools/bin 3)I h

Dec 20, 2021
A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode.

aliyun-dns A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode. Installation Install aliyun-cli. Usage $ aliyun-dns -h A wra

Dec 21, 2021
Symfony-cli - The Symfony CLI tool For Golang

Symfony CLI Install To install Symfony CLI, please download the appropriate vers

Dec 28, 2022
Go-file-downloader-ftctl - A file downloader cli built using golang. Makes use of cobra for building the cli and go concurrent feature to download files.

ftctl This is a file downloader cli written in Golang which uses the concurrent feature of go to download files. The cli is built using cobra. How to

Jan 2, 2022
Cli-algorithm - A cli program with A&DS in go!

cli-algorithm Objectives The objective of this cli is to implement 4 basic algorithms to sort arrays been Merge Sort Insertion Sort Bubble Sort Quick

Jan 2, 2022
Nebulant-cli - Nebulant's CLI
Nebulant-cli - Nebulant's CLI

Nebulant CLI Website: https://nebulant.io Documentation: https://nebulant.io/docs.html The Nebulant CLI tool is a single binary that can be used as a

Jan 11, 2022
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it

news-parser-cli Simple CLI which allows you to receive news depending on the par

Jan 4, 2022