fuego

package module
v0.0.0-...-5c764e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2019 License: BSD-3-Clause Imports: 11 Imported by: 2

README

Build Status GoDoc Go Report Card Coverage Status License

fuego

Inspired by Google python-fire

fuego is a library for automatically generating command line interfaces (CLIs) from function and struct.

Features

  • fuego is a simple way to create a CLI in Go.
  • fuego helps with exploring existing code or turning other people's code into a CLI. [1]
  • fuego shows documentation of each method or functions for help.

Installation

go get github.com/corona10/fuego

TODO

  • Support flag options
  • More error handling
  • Support more types

asciicast

Examples

package main

import (
	"fmt"

	"github.com/corona10/fuego"
)

func Add(a int, b int) (int, int) {
	fmt.Println(a, b)
	return a + b, 2*a + b
}

func main() {
	fuego.Fire(Add)
}
package main

import (
	"fmt"

	"github.com/corona10/fuego"
)

type Sample struct {
	Name string
}

func (s Sample) Add(a, b int) int {
	return a + b
}

func (s Sample) Minus(a, b int) int {
	return a - b
}

func (s Sample) HelloWorld() {
	fmt.Println(s.Name)
	fmt.Println("Hello world!")
}

func main() {
	var s Sample
	s.Name = "test"
	fuego.Fire(s)
}

Special thanks to

Documentation

Overview

Package fuego is a library for automatically generating command line interfaces (CLIs) from function and struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fire

func Fire(target interface{}, config ...Config) ([]reflect.Value, error)

Fire is a function for automatically generating command line interfaces (CLIs) from function and struct

Types

type Config

type Config struct {
	PrintReturnValuesOff bool
}

Config is a configuration struct for fuego

type Fkind

type Fkind int
const (
	// Unknown is a enum value of the unknown FuegoKind.
	Unknown Fkind = iota
	// Func is a enum value of the Func.
	Func
	// Method is a enum value of the Go's method.
	Method
)

type Sym

type Sym struct {
	// contains filtered or unexported fields
}

Sym is a symbol of method/functions

func (*Sym) Call

func (s *Sym) Call() []reflect.Value

func (*Sym) GetDoc

func (s *Sym) GetDoc() string

func (*Sym) GetIn

func (s *Sym) GetIn(idx int) reflect.Type

func (*Sym) GetNumIns

func (s *Sym) GetNumIns() int

func (Sym) GetNumOfNeededArgs

func (s Sym) GetNumOfNeededArgs() int

func (*Sym) IsValid

func (s *Sym) IsValid() bool

func (*Sym) SetCall

func (s *Sym) SetCall(call reflect.Value)

func (*Sym) SetDoc

func (s *Sym) SetDoc(doc string)

func (*Sym) SetKind

func (s *Sym) SetKind(kind Fkind)

func (*Sym) SetName

func (s *Sym) SetName(name string)

func (*Sym) SetParams

func (s *Sym) SetParams(params []string)

func (*Sym) SetValid

func (s *Sym) SetValid(valid bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL