Giter Club home page Giter Club logo

clir's Introduction

About

Github Stats

Top Languages Card

Working on

Wails xbar

clir's People

Contributors

deranjer avatar greyxor avatar leaanthony avatar marco-m avatar thetechpanda avatar tmclane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

clir's Issues

Why yet-another-CLI-framework™?

Hey,

your package looks promising in my eyes, I especially like the logo. However it is not clear to me, what the benefits of this yet-another-CLI-framework™ in comparsion to other cli-frameworks like commandeer or cobra are. Could you explain them a little bit?

Bash Completion support

Would be really nice. I recently started working on a wails project, which uses this library for its cli. It would be nice to have clir automatically generate a bash completion script. From my quick glance at the source, a modified copy of the PrintHelp function could do the job.

A use-case clarification needed

Hi guys,

We are currently evaluating a CLI utility to use with goxygen (a generator of web projects). I like the idea of a light-weight CLI utility that is straight forward and doesn't bring unneeded dependencies. That's why I thought we could try Clir. But I went through the Clirs documentation/examples and I can't figure out if it is capable of covering our use-case.

Soon we'll have to implement something like this:
goxygen init --frontend angular --db mysql my-new-app
or
goxygen init --frontend=angular --db=mysql my-new-app

The options for the flags would have to be validated against a predefined set of parameters. Say for the --frontend flag the options could only be angular,react and vue, etc.

Q: Can you please tell me if we can achieve this with Clir? Or how much of it can already be handled by the lib?

Thank you.

Best regards,
Sasha.

Flags not parsed when additional args are provided

Example:

package main

import (
	"fmt"
	"github.com/leaanthony/clir"
)

func main() {
	cli := clir.NewCli("test", "Test", "v0.0.0")
	s := cli.NewSubCommand("sub", "Desc")
	var f string
	s.StringFlag("f", "De", &f)
	s.Action(func() error {
		fmt.Println(f)
		return nil
	})
	cli.Run()
}

Command

go run main.go sub file -help

Expected output

test v0.0.0 - Test

test sub - Desc
Flags:

  -f string
        De
  -help
        Get help on the 'test sub' command.

Actual output


Update

It seems that if the additional argument is provided after the flags it just works fine. However I don't consider this a viable solution. Now I can see some parallels to #9.


I am going to address this in a PR.

custom flag errors + PrintHelp() suppression

As it stands the behaviour of the library when user inputs undefined flags is to print a. the error b. help.

While the above described approach is thoughtful default behaviour and I could achieve parity with say kubectl or docker or git for non existent commands like so

	cli.Action(func() error {
		w := cli.OtherArgs()
		return fmt.Errorf(`unknown command %q for %q
Run '%[2]s --help' for usage`, w[0], cli.Name())
	})

	if err := cli.Run(); err != nil {
		fmt.Printf("Error: %s\n", err)
	}
$ go run ./cmd/pilates wrong
Error: unknown command "wrong" for "pilates"
Run 'pilates --help' for usage

if I attempt to run $ go run ./cmd/pilates -w I can not suppress the help being printed or return custom messages. Maybe worse the error is hardcoded so I end up with the error printed twice without me being able to stop it.

$ go run ./cmd/pilates -w
Error: flag provided but not defined: -w  <--- #1 

 Pilates
     v0.0.1 - Ultimate Pilates Machine

Flags:

  -help
        Get help on the 'pilates' command.

Error: flag provided but not defined: -w   <--- #2

my proposal is all or anything of the following:

a. have an option to suppress printing help on undefined flags.

cli.SuppresHelp()

b. custom undefined flag errors. Return golang err followed by a custom error message. examples:

$ git -w
unknown option: -w
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

or

$ kubectl -w
Error: unknown shorthand flag: 'w' in -w
See 'kubectl --help' for usage.

c. fix what seems to be buggy behaviour in line 83 command.go by removing the fmt.Print.

fmt.Printf("Error: %s\n\n", err.Error())

Passing arguments

Is it possible to pass arguments to the cli?
E.g. I have a command like cli create test and I'd like the create cmd know that it has to create something named e.g. test.

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.