Skip to content

go cli : a easy command line project struct based on go-arg

License

Notifications You must be signed in to change notification settings

ccreater222/go-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-cli

a easy command line project struct based on go-arg

quickstart

example for go-cli


commands/
    test.go
main.go

main.go:

package main

import (
	cli "github.com/ccreater222/go-cli"
	_ "example.com/commands"
)

func main()  {
	cli.Run()
}

push.go

package commands

import (
	"fmt"
	"github.com/ccreater222/go-cli/common"
)

type PushCmd struct {

	Remote      string `arg:"positional"`
	Branch      string `arg:"positional"`
	SetUpstream bool   `arg:"-u"`
}

func (receiver PushCmd) Execute()  {
	fmt.Println(receiver.Remote)

}

func init()  {
	common.RegisterCmd("Scan",PushCmd{},"arg:\"subcommand:push\"")
}

translate to go-arg

func push(arg Push){
    fmt.Println(arg.Remote)
}

type PushCmd struct {
	Remote      string `arg:"positional"`
	Branch      string `arg:"positional"`
	SetUpstream bool   `arg:"-u"`
}
var args struct {
	Push     *PushCmd     `arg:"subcommand:push"`
	Quiet    bool         `arg:"-q"` // this flag is global to all subcommands
}

parsers = arg.MustParse(&args)
command := parsers.Subcommand()
if command == nil {
    parsers.WriteHelp(os.Stderr)
    return
}
if parsers.SubcommandName()=="push"{
    push(command)
}

About

go cli : a easy command line project struct based on go-arg

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages