Skip to content

Latest commit

 

History

History
78 lines (65 loc) · 1.83 KB

README.md

File metadata and controls

78 lines (65 loc) · 1.83 KB

Welcome to Clipper

Clipper works on top of Cobra.
It generates the go code cli declaration from manifest. Developper implements interface declared by Clipper.

Getting started

Install Clipper:

go install github.com/najeal/clipper/cmd/clipper@latest

Take a look to the examples

Take a look on the Wiki

The Wiki contains the manifest data types details

Manifest usage preview

Below you can see a manifest Clipper will use as input.
Calling clipper manifest.yaml will generate commands in the ./cmd path.
Then the main.go calls cmd.Execute(svc) passing a struct that implements the expected interface generated by clipper:

name: Printer
use: printer
short: printer fights the loneliness!
long: printer fight the loneliness!
flags:
  - name: lang
    type: string
    value: english
    usage: language for the greeting
    persistent: true
commands:
  - name: Run
    use: run
    short: print the language and the value passed by str flag
    runnable: true
    flags:
      - name: str-to-print
        type: string
        value: my loneliness !
        usage: string value to print
        shorthand: s

main.go:

package main

import (
	"fmt"
	"os"

	"github.com/najeal/clipper/examples/other/cmd"
	"github.com/spf13/cobra"
)

func main() {
	cmd.Execute(&Service{})
}

type Service struct{}

func (*Service) Run(cmd *cobra.Command, args []string) {
	lang, err := cmd.Flags().GetString("lang")
	if err != nil {
		panic(err.Error())
	}
	str, err := cmd.Flags().GetString("str-to-print")
	if err != nil {
		panic(err.Error())
	}
	fmt.Fprintf(os.Stdout, "lang: %s\nstr-to-print: %s!", lang, str)
}