clipper

module
v0.0.0-...-209f396 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: Apache-2.0

README

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)
}

Directories

Path Synopsis
cmd
clipper/gen
Code generated by clipper.
Code generated by clipper.
examples
cobra_flags/cmd
Code generated by clipper.
Code generated by clipper.
cobra_greet/cmd
Code generated by clipper.
Code generated by clipper.
cobra_subcommands/cmd
Code generated by clipper.
Code generated by clipper.
exitcodes/gen
Code generated by clipper.
Code generated by clipper.
flags/gen
Code generated by clipper.
Code generated by clipper.
full/gen
Code generated by clipper.
Code generated by clipper.
greet/gen
Code generated by clipper.
Code generated by clipper.
subcommands/gen
Code generated by clipper.
Code generated by clipper.
version/gen
Code generated by clipper.
Code generated by clipper.

Jump to

Keyboard shortcuts

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