Skip to content
This repository
Browse code

[CommandLine] Implement ArgumentDef.OldStyleArray, prototype

  • Loading branch information...
commit 2d08c768c1e4c12e55edcd641d0d32d429dc81b1 1 parent b090eff
Andrew Whitworth authored

Showing 1 changed file with 43 additions and 7 deletions. Show diff stats Hide diff stats

  1. +43 7 src/commandline/ArgumentDef.winxed
50 src/commandline/ArgumentDef.winxed
@@ -58,7 +58,8 @@ class Rosella.CommandLine.ArgumentDef
58 58 // definitions and the description message associated with each
59 59 function get_description(var sb = new 'StringBuilder')
60 60 {
61   - self.__get_description_internal(sb);
  61 + // TODO: Take a list of positional aliases and include those
  62 + self.__get_description_internal(self.raw_defs, sb);
62 63 return sb;
63 64 }
64 65
@@ -164,9 +165,8 @@ class Rosella.CommandLine.ArgumentDef.NewStyleHash : Rosella.CommandLine.Argumen
164 165 }
165 166 }
166 167
167   - function __get_description_internal(var sb)
  168 + function __get_description_internal(var raw_defs, var sb)
168 169 {
169   - var raw_defs = self.raw_defs;
170 170 int max = 0;
171 171 var fixed_defs = {};
172 172 for (string arg in raw_defs) {
@@ -194,19 +194,55 @@ class Rosella.CommandLine.ArgumentDef.NewStyleHash : Rosella.CommandLine.Argumen
194 194 }
195 195 }
196 196
  197 +// An array of simple text definitions, like GetOpt::Obj uses
197 198 class Rosella.CommandLine.ArgumentDef.OldStyleArray : Rosella.CommandLine.ArgumentDef
198 199 {
199 200 function OldStyleArray() { }
200 201
201   - function __get_description_internal(var sb)
  202 + function __get_description_internal(var raw_defs, var sb)
202 203 {
203   - var raw_defs = self.raw_defs;
204   - // TODO: This
  204 + for (int i = 0; i < elements(raw_defs); i++) {
  205 + string arg = raw_defs[i];
  206 + push(sb, " ");
  207 + push(sb, arg);
  208 + push(sb, "\n");
  209 + }
205 210 }
206 211
207 212 // Get a processed definition hash for an old-style array of arrays
208 213 function __prepare_arg_defs(var defs, var arg_defs, var aliases)
209 214 {
210   - // TODO
  215 + for (int i = i; i < elements(defs); i++) {
  216 + string arg_def = defs[i];
  217 + string arg_name;
  218 + string arg_type = "b"; // Default is a boolean flag
  219 + var raw_aliases = null;
  220 +
  221 + // Separate on the ':' the name(s) from the type
  222 + int eql_idx = index_of_substr(arg_def, ":");
  223 + if (eql_idx != -1) {
  224 + arg_type = substr(arg_def, eql_idx + 1);
  225 + arg_def = substr(arg_def, 0, eql_idx);
  226 + }
  227 +
  228 + // Different aliases for the same option are separated by '|'.
  229 + // Get the list of them and take one of them to be the canonical
  230 + // arg_name.
  231 + if (index_of_substr(arg_def, "|") != -1) {
  232 + raw_aliases = split("|", arg_def);
  233 + arg_name = raw_aliases.pop();
  234 + } else
  235 + arg_name = arg_def;
  236 +
  237 + // Verify that the type is acceptable
  238 + arg_type = self.__verify_arg_type(arg_name, arg_type);
  239 +
  240 + // Add all aliases to the list of aliases
  241 + arg_defs[arg_name] = arg_type;
  242 + if (raw_aliases != null) {
  243 + for (string alias in raw_aliases)
  244 + aliases[alias] = arg_name;
  245 + }
  246 + }
211 247 }
212 248 }

0 comments on commit 2d08c76

Please sign in to comment.
Something went wrong with that request. Please try again.