tomaz / gbcli Goto Github PK
View Code? Open in Web Editor NEWObjective C foundation tool command line interface library
Home Page: http://gentlebytes.com
License: MIT License
Objective C foundation tool command line interface library
Home Page: http://gentlebytes.com
License: MIT License
The podspec says its at version 1.1, but Cocoapods only has it up to version 1.0. Could you push the latest, please?
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);
}
(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.
Some proposals about additional argument forms that can be supported:
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
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.
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.
Could you consider tagging an initial release so that this may be used with CocoaPods or similar, please?
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
}
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?
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)
Maybe I am missing something, but I guess I expected that if a required parameter is not present that the parser would alert me of this issue (other than just writing the message to the console) so that I could terminate execution of the application immediately?
The header comments are out of date compared to the Readme. The code samples are now wrong as the method signatures have changed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.