pike.git / lib / modules / Arg.pmod

version» Context lines:

pike.git/lib/modules/Arg.pmod:37:   //!   //! @code   //! MyArguments args = MyArguments(argv);   //! @endcode   //!   //! See the documentation for @[OptLibrary] for details about the various   //! Opt classes.      #pike __REAL_VERSION__    + //! This class contains a library of parser for different type of + //! options.   class OptLibrary - //! +    {       //! Base class for parsing an argument. Inherit this class to create    //! custom made option types.    class Opt    {    constant is_opt = 1;    protected Opt next;    -  //! Should return 1 for set options or a string containing the -  //! value of the option. Returning 0 means the option was not set -  //! (or matched). To properly chain arguments parsers, return -  //! @expr{::get_value(argv, env, previous)@} instead of @expr{0@}, -  //! unless you want to explicitly stop the chain and not set this -  //! option. +  //! The overloading method should calculate the value of the +  //! option and return it. Methods processing @[argv] should only +  //! look at argv[0] and if it matches, set it to 0. Returning 0 +  //! means the option was not set (or matched). To properly chain +  //! arguments parsers, return @expr{::get_value(argv, env, +  //! previous)@} instead of @expr{0@}, unless you want to +  //! explicitly stop the chain and not set this option.    mixed get_value(array(string) argv, mapping(string:string) env, -  int|string previous) +  mixed previous)    {    if(next) return next->get_value(argv, env, previous);    return 0;    }       //! Should return a list of options that are parsed. To properly    //! chain argument parsers, return @expr{your_opts +    //! ::get_opts()@}.    array(string) get_opts()    {
pike.git/lib/modules/Arg.pmod:123:       protected void create(string _opt)    {    if( sizeof(_opt)>2 && has_prefix(_opt, "--") )    double = 1;    else if( sizeof(_opt)!=2 || _opt[0]!='-' || _opt=="--" )    error("%O not a valid option.\n", _opt);    opt = _opt;    }    -  mixed get_value(array(string) argv, mapping(string:string) env, mixed previous) +  mixed get_value(array(string) argv, mapping(string:string) env, +  mixed previous)    {    if( !sizeof(argv) ) return previous || ::get_value(argv, env, previous);       if( double )    {    if( argv[0]==opt )    {    argv[0] = 0;    return (int)previous+1;    }
pike.git/lib/modules/Arg.pmod:178:    class Env    {    inherit Opt;    protected string name;       protected void create(string _name)    {    name = _name;    }    -  mixed get_value(array(string) argv, mapping(string:string) env, mixed previous) +  mixed get_value(array(string) argv, mapping(string:string) env, +  mixed previous)    {    if( env[name] ) return env[name];    return ::get_value(argv, env, previous);    }       protected string __sprintf()    {    return sprintf("Arg.Env(%O)", name);    }    }
pike.git/lib/modules/Arg.pmod:204:    class Default    {    inherit Opt;    protected string value;       protected void create(string _value)    {    value = _value;    }    -  string get_value(array(string) argv, mapping(string:string) env, mixed previous) +  string get_value(array(string) argv, mapping(string:string) env, +  mixed previous)    {    return value;    }       protected string __sprintf()    {    return sprintf("Arg.Default(%O)", value);    }    }   
pike.git/lib/modules/Arg.pmod:226:    //! @tt{-x@} and x in a sequence like @tt{-axb@} will set the    //! variable to @expr{1@}. @tt{--foo=bar@}, @tt{-x bar@} and    //! @tt{-x=bar@} will set the variable to @expr{bar@}.    //!    //! @example    //! Opt debug = MaybeOpt("--debug");    class MaybeOpt    {    inherit NoOpt;    -  mixed get_value(array(string) argv, mapping(string:string) env, mixed previous) +  mixed get_value(array(string) argv, mapping(string:string) env, +  mixed previous)    {    if( !sizeof(argv) ) return previous || ::get_value(argv, env, previous);       if( double )    {    // --foo    if( argv[0]==opt )    {    argv[0] = 0;    return (int)previous+1;
pike.git/lib/modules/Arg.pmod:297:       //! Parses an option that has a parameter. @tt{--foo=bar@}, @tt{-x    //! bar@} and @tt{-x=bar@} will set the variable to @expr{bar@}.    //!    //! @example    //! Opt user = HasOpt("--user")|HasOpt("-u");    class HasOpt    {    inherit NoOpt;    -  mixed get_value(array(string) argv, mapping(string:string) env, mixed previous) +  mixed get_value(array(string) argv, mapping(string:string) env, +  mixed previous)    {    if( !sizeof(argv) ) return previous || ::get_value(argv, env, previous);       if( double )    {    // --foo bar    if( argv[0]==opt )    {    if( sizeof(argv)>1 )    {
pike.git/lib/modules/Arg.pmod:464:       }       //!    protected int(0..1) unhandled_argument(array(string) argv,    mapping(string:string) env)    {    return 0;    }    +  //!    protected mixed cast(string to)    {    switch( to )    {    case "mapping":    return values + ([ REST : argv ]);    case "array":    return argv;    }    return UNDEFINED;