Skip to content

Latest commit

 

History

History
109 lines (77 loc) · 2.05 KB

README.md

File metadata and controls

109 lines (77 loc) · 2.05 KB

quack

GoDoc Test

An interface driven cli lib for go.

Overview

Have you ever said

Why can't writing CLIs be as easy as defining a struct and writing a function?

Then quack is for you.

Integration with spf13/cobra

The Bind api creates a cobra.Command from the given structure. This allows for easy integration with existing cli's that use this framework.

Other framework support

Supporting other frameworks like urfave/cli would be pretty easy. Feel free to file an issue with your framework of choice if you want it added.

A simple command

main.go

type ToHex struct {
	Input int
}

func (t ToHex) Run() {
	fmt.Printf("%x", t.Input)
}

func main() {
	quack.MustBind("tohex", new(ToHex)).Execute()
}

Can now be run

go run main.go --input 12334
302e

A simple set of sub commands

examples/deeply_nested/main.go

package main

import "github.com/eliothedeman/quack"

type a struct {
}

func (a) SubCommands() quack.Map {
        return quack.Map{
                "b": new(b),
        }
}

type b struct {
}

func (b) SubCommands() quack.Map {
        return quack.Map{
                "c": new(c),
        }
}

type c struct {
        XX string `default:"YYY" short:"x"`
        Y  int    `help:"this is a help message"`
        Z  bool   `default:"true"`
}

func (c) Run([]string) {

}

func (c) Help() string {
	return "the nested c command"
}

func main() {
	quack.MustBind("nested", new(a))
}
go run examples/deeply_nested/main.go b -h
Usage:    b <cmd> [args]
      c the nested c command


go run examples/deeply_nested/main.go b c -h
Usage:    c [args]
        the nested c command
Flags:                                   
             --z         (default=true)  
Options:                                 
         -x, --xx string (default='YYY') 
             --y  int    (default=0)     this is a help message