Coder Social home page Coder Social logo

writ's People

Contributors

bobziuchkovski 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  avatar

writ's Issues

Overridable flag

E.g. if -a and -b are both specified then the last one specified will be used.

A workaround might be adding --mode option and specify --mode=a or --mode=b.

I'd propose to extend/change the OptionDecoder interface, where both option name and value are passed to the Decode function.

get filenames for io.Reader/io.Writer

Is it possible to get the filenames for io.Reader and io.Writer options? I like the automatic handling of them, but still prefer to sometimes get to the filenames (for error messages and the like)

Placeholder Silently Fails for non-string Options

Setting a placeholder:"<some-thing>" as a struct tag for types other thanstring` causes the option parsing to silently fail and omit that option:

type Config struct {
    # Included
    Start     int64  `option:"start-time" description:"The timestamp (in Unix seconds) to request logs from."`
    # Omitted (i.e. not parsed, not included in help text)
    End       int64  `option:"end-time" placeholder="<unix-timestamp>" description:"The timestamp (in Unix seconds) to request logs to."`
    # Included  Count     int    `option:"c, count" default:"1" description:"The number (count) of logs to retrieve."`
}

Is this intended? Can be useful to describe formatting.

Error message for subcommand is wrong

$ cat test.go

package main

import (
        "os"

        "github.com/bobziuchkovski/writ"
)

type Foo struct {
        Bar Bar `command:"bar"`
}

type Bar struct {
        HelpFlag bool `flag:"h, help"`
}

func main() {
        foo := &Foo{}
        cmd := writ.New("foo", foo)
        path, _, err := cmd.Decode(os.Args[1:])
        if err != nil {
                path.Last().ExitHelp(err)
        }
}

$ go run test.go bar --help --help

Usage: foo bar [OPTION]... [ARG]...

Error: option "bar" specified too many times
exit status 1

I believe the error message should be option "help" specified too many times

Option.Default field?

Has an Option.Default field been considered? I prefer to write options without struct tags (since struct tags aren't checked by the compiler, leading to my issue yesterday), but right now you need to write the following:

    {
        Names:       []string{"count"},
        Description: "The (maximum) number of logs to request.",
        Placeholder: "<num>",
        Decoder:     writ.NewDefaulter(writ.NewOptionDecoder(config.Count), "1"),
    },

This isn't bad, but it:

  • Limits you to strings - if the field is an int64 or other time (say, for Unix timestamps) then you can't set a default.
  • A Default field would be more explicit and would better map against the existing struct tag names.

Support Embedded Structs for Commands

This allows you to have a common set of options/flags across sub-commands - e.g.

type Common struct {
    FileName string
    Headers string
    ...
}

type Fetch struct {
    Common
    From string
}

type Restore struct {
    Common
    To []string
}

The structs here are simple, but should illustrate the use-case. The embedded struct does not seem to be parsed.

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.