Skip to content

A couple of enhancements... #7

@stevewi-niteflyte

Description

@stevewi-niteflyte
  1. Implement OptionParser.Separator() to be able to insert stuff in the --help output programmatically (e.g., newlines). See the Ruby doc.

  2. I have a program (called opt) that validates a shell script command line against specification provided in a JSON file. Here's a snippet:

{
   "xyzzy": {
        "short": "x",
        "desc": "Set the xyzzy",
        "type": "range",
         "value": "0..5",
        "default": 3
    }
}

This specification defines -x, --xyzzy as a range. The value of -r, --range must be an integer in the range (0..5) with a default of 3.

I use ParseFrom() to supply the shell script command line to my Go program (via the OptionParser.Extra data). I have a command line flag on my Go program that sets the script name:

opt -f jsonfile.json -n scriptName -- --the script --args

Hopefully, you get the idea...

Lets say that I supply an non-existent argument as part of the Extra(); e.g.

opt -f jsonfile.json -n scriptName -- --the script --args --nonexistent

The map sent to ParseFrom() is [scriptHame --the script --args --nonexistent]. I have a couple of lines of code to ensure that the first item in the map is scriptName.

ParseFrom() generates the appropriate error (as it should):

opt: unknown option nonexistent

I would like this message to be:

scriptName: unknown option nonexistent

So, in a nutshell, if you parse args with ParseFrom(foo), any error messages that ParseFrom() generates should use foo[0] as the program name.

I hope this is clear. Please reply if you have questions.

Thanks in advance...

P.S. It's a simple matter to make foo[0] the program name:

foo := op.Extra
foo = append([]string{"scriptName"}, foo...)

If op.Extra has [--the script --args --nonexistent], foo will have [scriptHame --the script --args --nonexistent].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions