[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Select a startup class from the command line
[Thread Prev] | [Thread Next]
- Subject: Re: Select a startup class from the command line
- From: Bruce Steers <bsteers4@xxxxxxxxx>
- Date: Tue, 22 Apr 2025 13:21:37 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
On Tue, 22 Apr 2025 at 12:20, BB <adamnt42@xxxxxxxxx> wrote: > > On 22/4/25 7:27 pm, Bruce Steers wrote: > > > > On Tue, 22 Apr 2025 at 10:35, Bruce Steers <bsteers4@xxxxxxxxx> wrote: > >> >> >> On Tue, 22 Apr 2025 at 06:04, BB <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 > I dunno, with the simple above mentioned modification to Args.module you could easily use gb.args to process the standard way (including multiple flags like -xyz) The mod will make a number beginning with - get added to aRestOfArgs so then a simple run through the rest of the unprocessed args weather show -67.42137331544458 164.77271477068862 -l zu the -l flag will be omitted leaving aRestOfArgs as ["show", "-67.42137331544458", "164.77271477068862", "zu"] So something like.. Dim sArg As String Dim aCoords As New Float[] For c As Integer = 0 to aRestOfArgs.Max sArg = aRestOfArgs[c] If sArg Like "show" Then bShowMode = True Else if IsFloat(sArg) Then aCoords.Add(cFloat(sArg)) Else If aCountryCodes.Exist(sArg) Then ' maybe match to a country code list? sLocale = sArg Else Print "Unknown arg: " & Shell(sArg) Endif Next Also thanks to my tinkering with gb.args you can now manage your own help texts to further explain beyond the automatically printed items from args.Has/Args.Get/etc. if you use "*If Args.Has("h","help","Print this help")*" then help is not automatically printed. the automatic help text can then be obtained using Args.HelpText() (AFTER Args.End) and your own further details added. Eg. Args.Begin(File.Name(Args[0]) & " [show/edit] <params> [coords] [locale]") If Args.Has("h","help","Print this help") Then bPrintHelp = True aRestOfArgs = Args.End() If bPrintHelp Then Print Args.HelpText() ' help for all the handled params Print "blah blah show to open inteface" Print "blah blah coordinates" Print "Example..." Print "blah blah blah" Quit Endif Respects BruceS
Select a startup class from the command line | BB <adamnt42@xxxxxxxxx> |
Re: Select a startup class from the command line | Bruce Steers <bsteers4@xxxxxxxxx> |
Re: Select a startup class from the command line | Bruce Steers <bsteers4@xxxxxxxxx> |
Re: Select a startup class from the command line | BB <adamnt42@xxxxxxxxx> |