add sanitizedArguments to SOGoTool
sanitizedArguments are the arguments received on the CLI minus those that are part of the NSArgumentDomain For example: sogo-tool user-preferences set sogo1 -p /tmp/creds Vacation -f /tmp/json arguments would contain: @"set", @"sogo1", @"-p", @"/tmp/creds", @"Vacation", @"-f", @"/tmp/json" sanitizedArguments would contain : @"set", @"sogo1", @"Vacation"pull/7/head
parent
b838734756
commit
6f8d8394df
|
@ -31,6 +31,7 @@
|
|||
{
|
||||
BOOL verbose;
|
||||
NSArray *arguments;
|
||||
NSArray *sanitizedArguments; /* arguments w/o args from NSArgumentDomain */
|
||||
}
|
||||
|
||||
+ (NSString *) command;
|
||||
|
@ -40,6 +41,7 @@
|
|||
verbose: (BOOL) isVerbose;
|
||||
|
||||
- (void) setArguments: (NSArray *) newArguments;
|
||||
- (void) setSanitizedArguments: (NSArray *) newArguments;
|
||||
- (void) setVerbose: (BOOL) newVerbose;
|
||||
- (BOOL) run;
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@
|
|||
*/
|
||||
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSCharacterSet.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSUserDefaults.h>
|
||||
|
||||
#import "SOGoTool.h"
|
||||
|
||||
|
@ -49,6 +51,7 @@
|
|||
[instance autorelease];
|
||||
|
||||
[instance setArguments: toolArguments];
|
||||
[instance setSanitizedArguments: toolArguments];
|
||||
[instance setVerbose: isVerbose];
|
||||
|
||||
return [instance run];
|
||||
|
@ -59,6 +62,7 @@
|
|||
if ((self = [super init]))
|
||||
{
|
||||
arguments = nil;
|
||||
sanitizedArguments = nil;
|
||||
verbose = NO;
|
||||
}
|
||||
|
||||
|
@ -70,6 +74,44 @@
|
|||
ASSIGN (arguments, newArguments);
|
||||
}
|
||||
|
||||
- (void) setSanitizedArguments: (NSArray *) newArguments
|
||||
{
|
||||
NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
|
||||
NSString *argsString = [newArguments componentsJoinedByString:@" "];
|
||||
NSDictionary *cliArguments;
|
||||
|
||||
/* Remove NSArgumentDomain -key value from the arguments */
|
||||
cliArguments = [[NSUserDefaults standardUserDefaults]
|
||||
volatileDomainForName:NSArgumentDomain];
|
||||
for (NSString *k in cliArguments)
|
||||
{
|
||||
NSString *v = [cliArguments objectForKey:k];
|
||||
NSString *argPair = [NSString stringWithFormat:@"-%@ %@", k, v];
|
||||
argsString = [argsString stringByReplacingOccurrencesOfString: argPair
|
||||
withString: @""];
|
||||
}
|
||||
if ([argsString length])
|
||||
{
|
||||
/* dance to compact whitespace */
|
||||
NSArray *wordsWP = [argsString componentsSeparatedByCharactersInSet: whitespaces];
|
||||
NSMutableArray *words = [NSMutableArray array];
|
||||
for (NSString *word in wordsWP)
|
||||
{
|
||||
if([word length] > 1)
|
||||
{
|
||||
[words addObject:word];
|
||||
}
|
||||
}
|
||||
argsString = [words componentsJoinedByString:@" "];
|
||||
ASSIGN (sanitizedArguments, [argsString componentsSeparatedByString:@" "]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSIGN (sanitizedArguments, nil);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) setVerbose: (BOOL) newVerbose
|
||||
{
|
||||
verbose = newVerbose;
|
||||
|
|
Loading…
Reference in New Issue