shark

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: Apache-2.0 Imports: 4 Imported by: 2

README

Logo

Installation

Install cobrax with go module.

 go get github.com/coolstina/shark

Features

  • Use option design model definition command.
  • Use callback function addition flags.
  • Fast build client application.

Usage/Examples

Step1: Build client application

package main

import (
	"fmt"

	"github.com/coolstina/shark"
)

func main() {
	sharkcmd := shark.NewShark(
		shark.WithUse("hello"),
		shark.WithLong("Say hello"),
		shark.WithLong("Execute this command output say hello"),
		shark.WithRun(func(cmd shark.Command, args []string) {
			fmt.Printf("hello world")
		}),
	)

	if err := sharkcmd.Command().Execute(); err != nil {
		fmt.Printf("%s\n", err.Error())
	}
}

Step2: Install client application

go install ./example

Step3: Run client application on terminal

View help information:

$ example -h
Execute this command output say hello

Usage:
  hello [flags]

Flags:
  -h, --help   help for hello

Execute command:

$ example hello
hello world

Authors

License

Apache

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CheckErr = cobra.CheckErr
View Source
var EnableCommandSorting = func(enabled bool) {
	cobra.EnableCommandSorting = enabled
}

Functions

This section is empty.

Types

type Command

type Command = *cobra.Command

type CompletionOptions

type CompletionOptions = cobra.CompletionOptions

type FlagSet

type FlagSet = *pflag.FlagSet

type FlagSetFunc

type FlagSetFunc = func(flags FlagSet)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithCompletionOptions

func WithCompletionOptions(completionOptions CompletionOptions) Option

WithCompletionOptions specify completion options.

func WithLong

func WithLong(long string) Option

WithLong Use specific parameter for long value override original value.

func WithRun

func WithRun(run RunFunc) Option

WithRun Use specific parameter for run value override original value.

func WithShort

func WithShort(short string) Option

WithShort Use specific parameter for short value override original value.

func WithUse

func WithUse(use string) Option

WithUse Use specific parameter for use value override original value.

type RunFunc

type RunFunc func(cmd Command, args []string)

type Shark

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

func NewShark

func NewShark(ops ...Option) *Shark

NewShark Shark is the cobra command structure wrapper.

func (*Shark) Command

func (super *Shark) Command() Command

func (*Shark) SetFlags

func (super *Shark) SetFlags(set FlagSetFunc)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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