go-cli

command module
v1.1.17 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 3 Imported by: 0

README

go-cli

GoCI codecov Go Report Card

CLI tool for Golang.

Install

go install github.com/xuender/go-cli@latest

init

Initialize the Golang project and create a default configuration file.

git clone url
cd dir
go-cli init
github

Initialize the github configuration files.

git-cli init github
gitee

Initialize the gitee configuration files.

git-cli init gitee

Use template.

go-cli init newName

generate

Generate source code including commands, tests, examples, structures, protobuf, etc.

cmd

Generate command support cobra and flag.

go-cli g c cmdName
go-cli g c cmdName -t flag
go-cli g c cmdName -t cobra
struct

Generate struct and new function.

go-cli g s pkg/Book
interface

Generate interface and comments.

go-cli g i pkg/Book
test

Generate unit tests for exposed functions in file or directory.

go-cli g t pkg/book.go
example

Generate test examples for exposed functions in file or directory.

go-cli g e pkg/book.go
proto

Generate protobuf and comments.

go-cli g p pb/Book
go-cli g p pb/BookType -t enum

struct

Struct related.

new

Create a new struct function by other struct.

go-cli s n book/book.go pb/book.pb.go
// NewBookByPbBook creates a new Book of pb.Book.
func NewBookByPbBook(elem *pb.Book) *Book {
  return &Book{
    ID:    elem.ID,
    Title: elem.Title,
  }
}

convert

Convert struct to other structs.

go-cli s c book/book.go pb/book.pb.go
// FromPbBook from pb.Book.
func (p *Book) FromPbBook(elem *pb.Book) *Book {
  p.ID = elem.ID
  p.Title = elem.Title

  return p
}

// ToPbBook to pb.Book.
func (p *Book) ToPbBook() *pb.Book {
  return &pb.Book{
    ID:    p.ID,
    Title: p.Title,
  }
}

template

Initialize template.

go-cli template 

Edit ~/.config/go-cli/*/*.tpl

New Initialization Template
mkdir ~/.config/go-cli/newName
vi ~/.config/go-cli/newName/xxx.tpl
# initialize by newName
go-cli init newName

License

© xuender, 2022~time.Now

MIT License

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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