Coder Social home page Coder Social logo

gbcli's People

Contributors

ashton-w avatar bjornbytes avatar stuclift avatar tgymnich avatar tomaz avatar uranusjr 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gbcli's Issues

Update Cocoapod

The podspec says its at version 1.1, but Cocoapods only has it up to version 1.0. Could you push the latest, please?

Add stderr options for gbprint output

Please add the option to output to stderr.

Something like:

void gbprinterr(NSString *format, ...) {
va_list arguments;
va_start(arguments, format);
gb_printf_worker(stderr, format, arguments);
va_end(arguments);
}

void gbprinterrln(NSString *format, ...) {
va_list arguments;
va_start(arguments, format);
format = [format stringByAppendingString:@"\n"];
gb_printf_worker(stderr, format, arguments);
va_end(arguments);
}

--no-whatever option doesn't work

(I'm using the default GBCli from CocoaPods (1.1?) with Objective-C on a Mac OS X 10.10 system running Xcode 6.2.)

I added an option that needs a negative variant. I'm using a settings object that has the corresponding property set to YES by default. Using "--no-myOption" doesn't turn off the feature, although "--myOption=0" does.

I looked into the section of GBCommandLineParser.m that handles the "--no-" options. The debugger shows that the "--no-" variant is being registered. Then I checked into the part of the file that handles writing the option's value into the results dictionary. The write occurs, but it's under the "no-myOption" key. That's the bug; my code never sees the change since the regular and negative variants are supposed to use the same key.

Support more argument forms

Some proposals about additional argument forms that can be supported:

Syntax to explicitly signal end of options

If a non-option argument needs to start with -, we need a way to tell the parser to explicitly treat it that way. To solve this, it is common to use a special option (usually - or --) to signal end of options. So for the following:

cmd --option1 --option2 -- --arg1 arg2

will be parsed as

Arguments:
    --arg1
    arg2

Options:
    option1
    option2

Interlacing arguments and options

Many applications accept a more permissive argument form, like this:

cmd arg1 --option=value arg2 arg3

while GBCli currently requires it to be written as

cmd --option=value arg1 arg2 arg3

instead.

I think this can be implemented quite easily. Currently the parser terminates parsing immediately when a non-option argument is met. If this is not the case, interlacing can happen.

Means to add auto-creation of negative variant

The negative variant of GBValueNone options is nice, but there are times when that is not really wanted. How about an extra method to let the user specify explicitly whether the negative variant should be created?

I’m not sure how this should be implemented though. Maybe something like

- (void)registerOption:(NSString *)longOption
              shortcut:(char)shortOption
           requirement:(GBValueRequirements)requirement
   addsNegativeVariant:(BOOL)addsNegativeVariant

Looking forward to hear how you feel about these improvements. I have tried to implement the interlacing feature. Although not thoroughly tested yet, I think it works. If you feel okay with the above I’ll start working on the other parts and submit a pull request afterwards.

CocoaPods

Could you consider tagging an initial release so that this may be used with CocoaPods or similar, please?

I need a simple, complete minimal example

Hi,

I need to add parameters support to a tool I am writing. So instead of fighting with getopt_long as usual, I am looking for a higher level solution. GBCli looks like it can do that for me.

However, I am having some trouble to use it. What I am trying to get is a command line options support that can process several options without values, like --souligne --souligne-double --souligne-vague, etc.

I don't need support for configuration file, default or anything else. Just a way to know which options have been used.

Using your examples, I did manage to declare the options, but now I am struggling to process them. Could you help me, please ?

My code is the following:

#import <Foundation/Foundation.h>

#import "GBSettings+Application.h"
#import "GBCommandLineParser.h"
#import "GBOptionsHelper.h"


void registerOptions(GBOptionsHelper *options) {
    GBOptionDefinition definitions[] = {
        {'?',GBSettingKeys.printHelp,@"Affiche cette aide et termine",GBValueNone|GBOptionNoPrint},
        { 0, nil, nil, 0 }
    };
    [options registerOptionsFromDefinitions:definitions];
}

int main(int argc, char **argv) {

    @autoreleasepool {

        // Initialize settings stack.
        GBSettings *factoryDefaults = [GBSettings mySettingsWithName:@"Factory" parent:nil];
        GBSettings *fileSettings = [GBSettings mySettingsWithName:@"File" parent:factoryDefaults];
        GBSettings *settings = [GBSettings mySettingsWithName:@"CmdLine" parent:fileSettings];
        [factoryDefaults applyFactoryDefaults];

        // Initialize options helper class and prepare injection strings.
        GBOptionsHelper *options = [[GBOptionsHelper alloc] init];
        registerOptions(options);

        // Initialize command line parser and register it with all options from helper. Then parse command line.
        GBCommandLineParser *parser = [[GBCommandLineParser alloc] init];

        // Create parser and register all options.
        [options registerOption:'s' long:@"souligne" description:@"Souligne le textex" flags:GBValueNone];
        [options registerOption:'S' long:@"souligne-double" description:@"Double souligne le texte" flags:GBValueNone];
        [options registerOption:'v' long:@"souligne-vague" description:@"Souligne le texte avec une vague" flags:GBValueNone];



        [options registerOptionsToCommandLineParser:parser];
        __block BOOL commandLineValid = YES;
        [parser parseOptionsWithArguments:argv count:argc block:^(GBParseFlags flags, NSString *option, id value, BOOL *stop) {
            switch (flags) {
                case GBParseFlagUnknownOption:
                    printf("Option %s inconnue, utilisez --help pour obtenir l’aide\n", option.UTF8String);
                    commandLineValid = NO;
                    break;
            }
        }];

        if (!commandLineValid)
            return EXIT_FAILURE;

        // Print help or version if instructed - print help if there's no cmd line argument also...
        if (settings.printHelp || argc == 1) {
            [options printHelp];
            return EXIT_SUCCESS;
        }

// OK, but now… ?

        if @"souligne" exists {
            do.something();
        }

        if @"souligne-double" exists {
            do.something();
        }

        if @"souligne" exists {
            do.something();
        }


        return EXIT_SUCCESS;
    } // fin @autoreleasepool

}

Error message for `GBParseFlagMissingValue` prints garbage

I am using v1.1 from Cocoapods. When I don't specify a value for a required argument, I get

Missing value for command line option ò·;Æˇ�, try --help!

Looking into this, I see that you have fixed this issue 2 years ago, but haven't release a version to Cocoapods. Any chance that you could cut a release at some point with these latest fixes? Even a 1.1.1?

Short options as strings

I find that using chars for the short options, while technically correct, is a bit convoluted, specially since they are later converted to NSStrings anyway. I'd request to have additional methods in which short options are declared as NSStrings, as that would make them more usable from Swift (where getting hold of a single char is a pain)

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.