Code Monkey home page Code Monkey logo

cli's People

Contributors

ymgyt avatar

Stargazers

 avatar

Watchers

 avatar  avatar

cli's Issues

add Command.Clone() method

for concurrently safe, Command need clone method.

Usage Example

func (h *Handler) Handle(res *Response, req *Request) {
  cmd := h.commandProtoType.Clone()
  cmd.Stdout, cmd.Stderr = res.Writer
  cmd.ExecuteWithArgs(ctx, req.Args)

prompt feature

like this

import "github.com/ymgyt/cli/prompt"

func doSomething() {
   ok, err := prompt.New().
     Display("are you sure?[y/n]").
     Require("y", "yes").
     CaseInsentive().
     Timeout(10*time.Second).
     Prompt()

  if ok {
    // continue process...
  }
  log.Fatal("user cancel process")
}

when test

b := bytes.NewBufferString("yes")
got, err := prompt.New().
  ReadFrom(b).
  WriteTo(ioutil.Discard).
  Display("give me yes").
  Require("yes").
  Prompt()
if got != true {
 t.Fatal("fail")
}

TODO

  • merge parent command flagset
  • test coverage
  • curl -sSLO <target> support
  • float, ints, url flag support
  • refactor command parse method
  • circleci config
  • coverage readme budge
  • README update

check Command.Run nil before execute

func (c *Command) ExecuteWithParseResult(ctx context.Context, pr *parser.Result) {
	var runCmd = c
	for _, sub := range pr.Commands() {
		if runCmd == nil {
			panic("runCmd == nil, something went wrong")
		}
		runCmd = runCmd.Lookup(sub)
	}
	if err := runCmd.ConsumeFlags(pr.AllFlags()); err != nil {
		c.handleParseErr(err)
		return
	}
        // NEED nil check HERE !!!
	runCmd.Run(ctx, runCmd, pr.Args())
}

allow multi value on ints/strings option

like that

cmd --ints-option=100,200,300

# currently only allowed
cmd --int-option=100  --int-option=200 --int-option=300

and allow user specify delimiter (default ,)

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.