cli

package module
v0.0.0-...-f24c060 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: MIT Imports: 4 Imported by: 0

README

Cli

Simple console cli

cmd/example

package main

import (
	"github.com/alexsuslov/cli"
	"os"
)

func main() {
	if err := cli.
		New("cli", "Example Cli").
		Action(os.Args); err != nil {
		panic(err)
	}
}
> go run cmd/example/example.go
Example Cli
---
> cli help
return this help

Add Action

AddAction

- command   // string
- action    // function func(args []string)error
- help      // template help
    New("covid-cli", "ECDC - RSS - COVID-19").
		AddAction("all", All(feedUrl), helpTemplate).
		AddAction("json", Json(feedUrl), helpJsonTemplate)

cmd/example1

 go run cmd/example1/example.go json | jq

{
  "title": "ECDC - RSS - COVID-19",
  "link": "https://www.ecdc.europa.eu/en",
  "language": "en",
  "items": [
    {
      "title": "Rapid Risk Assessment: Resurgence of reported cases of COVID 19 in the EU/EEA, the UK and EU candidate and potential candidate countries",
      "description": "While decreasing trends in disease incidence are being observed in Europe overall (12% decrease in 14-day incidence of reported cases between 16 and 30 June), there is still community transmission reported in most EU/EEA countries, the UK and EU candidate and potential candidate countries. Additionally, some countries are reporting a resurgence of observed cases or large localised outbreaks.",
      "link": "https://www.ecdc.europa.eu/en/publications-data/rapid-risk-assessment-resurgence-reported-cases-covid-19",
      "published": "Thu, 02 Jul 2020 14:00:00 +0200",
      "publishedParsed": "2020-07-02T12:00:00Z",

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionFn

type ActionFn func(args []string) error

type Cli

type Cli struct {
	Values   map[string]string
	Actions  map[string]ActionFn
	Template map[string]*template.Template
	Helps    []string
	// contains filtered or unexported fields
}

func New

func New(name string, title string) *Cli

New cli with Title in help

func (*Cli) Action

func (Cli *Cli) Action(args []string) error

func (*Cli) AddAction

func (Cli *Cli) AddAction(command string, action ActionFn, help string) *Cli

func (Cli) Errorf

func (Cli Cli) Errorf(format string, v ...interface{})

func (*Cli) Help

func (Cli *Cli) Help(args []string) error

func (*Cli) IsErr

func (Cli *Cli) IsErr(errs ...error) bool

func (Cli) Printf

func (Cli Cli) Printf(format string, v ...interface{})

func (Cli) Println

func (Cli Cli) Println(v ...interface{})

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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