[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Select a startup class from the command line



On 22/4/25 7:27 pm, Bruce Steers wrote:


On Tue, 22 Apr 2025 at 10:35, Bruce Steers <bsteers4@xxxxxxxxx <mailto:bsteers4@xxxxxxxxx>> wrote:



    On Tue, 22 Apr 2025 at 06:04, BB <adamnt42@xxxxxxxxx
    <mailto:adamnt42@xxxxxxxxx>> wrote:

        Is this possible?

        Some programs run different interfaces depending on the
        "command" specified on the command line, notably (or perhaps
        notoriously) "apt". Such as:

        apt get <params> apt install <params> apt
        this-that-and-the-other <params>

        In my case, I'm trying to develop a library to interface to
        the OpenWeatherMap feed. It will have 3 modes of operation (so
        far):

          * as a library called from a client application, via an
            exposed interface class "Weather"
          * as a normal executable to allow the user to setup some
            configuration data, such as language, API key, etc
          * as a normal executable that just shows the weather for a
            location through a small UI

        For the latter two then I want to specify which interface to
        use is a similar way to the "apt" command:

          * weather configure
          * weather [show] <location params>
            /[show] is optional, if included, the data is just printed
            on stdout/

        Note, this is different from the normal usage of the gb.args
        component where the "options" must come before the
        "arguments". Here I have a syntax of

             weather <command>  <args> <options>

        So for example,

             weather show -67.42137331544458, 164.77271477068862 -l zu

        would print the current weather conditions on Sturge Island to
        stdout in the zulu language (should I ever require it 😕).

        tia

        bruce


    Not quite sure the exact problem but to answer some questions...

    the -s arg sets startup class with gbx3 and gbr3 but you would
    then need to use gbr3 prefix on an executable to give the -s arg
    and not call the executable directly.


    Args can come after params using Args.class  Args.End()
    -------------
    Dim aRestOfArgs As String[]
    Dim bBoolParam As Boolean
    Args.Begin()
    bBoolParam = Args.Has("b", "bool", "bool param")

    aRestOfArgs = Args.End()
    -------------

    aRestOfArgs[] is now ALL the other remaining args supplied after
    the ones processed between Begin and End are removed. these can be
    examined and dealt with accordingly.

    Does that help?
    Respects
    BruceS


Hmm after saying that i realize Args.class will probably fail with an argument like -67.42137331544458
"Unknown option -6"

But then there is not much to gb.args when it comes to copying the Args.module file into your project and modifying it to suit your needs.
Maybe change line 61 from this...
|If Len(sArg) > 1 And If Left(sArg) = "-" Then
|
To this...
|If Len(sArg) > 1 And If Left(sArg) = "-" And If IsLetter(sArg[1]) Then|||

that way only letters not numbers work with - sign

Respects
BruceS

Yep, all of the above. Maybe I'll have to eshew gb.args and parse the damn thing just using Args (the one that gets overridden by gb.args).

Damnably frustrating. All I want (haha) is simply "positional cli arguments" with all the features of gb.args! Hmm, maybe I could just scan the commend line, split the sub-command and then pass the remainder to gb.args somehow or other.

Continuing to thrash.

regards

b


Follow-Ups:
Re: Select a startup class from the command lineBruce Steers <bsteers4@xxxxxxxxx>
Re: Select a startup class from the command lineLee <t.lee.davidson@xxxxxxxxx>
References:
Select a startup class from the command lineBB <adamnt42@xxxxxxxxx>
Re: Select a startup class from the command lineBruce Steers <bsteers4@xxxxxxxxx>
Re: Select a startup class from the command lineBruce Steers <bsteers4@xxxxxxxxx>