Giter VIP home page Giter VIP logo

go-cmder's Introduction

go-cmder

A command from struct generator.

Installation

go install github.com/donatorsky/go-cmder@latest

Usage

go-cmder [flags] struct CommandName

Flags

-constructor=name[:field1,fieldn...]

Defines a name and comma-separated list of fields for command constructor. Multiple usage allowed to generate many constructors.

A name is appended to the command name. E.g. given command name MyCmd, then -constructor=WithFoo generates func NewMyCmdWithFoo. Use name default to generate constructor based on command name. E.g. given command name MyCmd, then -constructor=default generates func NewMyCmd.

List of fields can be omitted to generate constructor without fields.

-exclude=field

Excludes given struct field from command generation. Multiple usage allowed.

-include=field

Includes given struct field in command generation. When present, command is generated only from included fields. Supersedes -exclude flag. Multiple usage allowed.

-include-unexported

Includes unexported fields when generating a command.

-mutable

Generates a mutable command. By default, commands are immutable, meaning that calling a setter returns new command instance.

-out=path/to/file.go

Generates a command in given file. By default, command is generated in command_name.go file.

-sorted

Sort fields by name when generating a command.

Example

package foobar

//go:generate go-cmder -constructor=default Struct CreateStructCmd
type Struct struct {
	Foo string
	Bar int
}

Generates create_struct_cmd.go file:

package foobar

type CreateStructCmd struct {
	vFoo string
	hasFoo bool

	vBar int
	hasBar bool
}

func NewCreateStructCmd() CreateStructCmd {
	return CreateStructCmd{}
}

func (cmd CreateStructCmd) Foo() string {
	return cmd.vFoo
}

func (cmd CreateStructCmd) SetFoo(v string) CreateStructCmd {
	cmd.hasFoo = true
	cmd.vFoo = v

	return cmd
}

func (cmd CreateStructCmd) HasFoo() bool {
	return cmd.hasFoo
}

func (cmd CreateStructCmd) Bar() int {
	return cmd.vBar
}

func (cmd CreateStructCmd) SetBar(v int) CreateStructCmd {
	cmd.hasBar = true
	cmd.vBar = v

	return cmd
}

func (cmd CreateStructCmd) HasBar() bool {
	return cmd.hasBar
}

go-cmder's People

Contributors

donatorsky avatar

Stargazers

Maksymilian Lewicki avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.