Autore Topic: Aggiunto nuovo componente ''gb.args''  (Letto 832 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.287
  • Ne mors quidem nos iunget
    • Mostra profilo
Aggiunto nuovo componente ''gb.args''
« il: 16 Ottobre 2012, 10:49:11 »
Minisini rende noto che è stato aggiunto un nuovo componente:


Hi,

In the last revision, I added a new component 'gb.args', which replaces
the unmaintained 'gb.option'. By the way, does anyone use 'gb.option'?

The goal of this component made in Gambas is analyzing the command-line
arguments and return the value of options.

It works like that:

' Start the analyze : UsageString is an optional string describing
' the global syntax of the command with its name.

Args.Begin(UsageString)

' This method returns if an option is present or not, with the form
' "-s" or "--long"

Args.Has("s", "long", ("description"))

' This method defines an option that takes one string argument, and
' returns it.

Args.Get("s", "long", ("description"), ("argument name"))

' This method defines an option that takes one integer argument, and
' returns it. The argument can be prefixed by "0x" for an hexadecimal
' number.

Args.GetInteger("s", "long", ("description"), ("argument name"),
   DefaultValue)

' This method ends the analyze, and returns all extra arguments (that
' usually are file paths to process). The arguments are returned into
' a String array.

Args.End()

Moreover, the End() method automatically handles:

- An '-h/--help' option that prints the program usage by using the usage
string sent to the Begin() function and all option descriptions.

- A '-V/--version' option that prints the program version.

Tell me what you think about that component!

Regards,

--
Benoît Minisini
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Aggiunto nuovo componente ''gb.args''
« Risposta #1 il: 16 Ottobre 2012, 12:43:59 »
Non ho più testato la lettura dei parametri, ma a suo tempo non si potevano passare dati preceduti dai classici trattini, perchè di uso strettamente privato ai parametri di gbx e gambas.
Se hanno reso libera questa cosa, allora è un gran passo avanti, e si può gestire gambas anche a livello di batch e/o gestire in modo serio i parametri passati all'Application.

Da quello che ho visto, hanno rilasciato una nuova release 3.x.
Provvedo stasera a scaricare e installare, e vedo meglio di cosa si tratta...

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.287
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Aggiunto nuovo componente ''gb.args''
« Risposta #2 il: 16 Ottobre 2012, 23:07:28 »
Poiché il nuovo componente andrà a sostituire il precedente gb.option, qualcuno nella M.L.I. ha fatto notare a Minisini di aver utilizzato quel componente nei suoi applicativi. Chiede pertanto come deve comportarsi con l'avvento del nuovo componente gb.args. Minisini così risponde:

« gb.option won't disappear until a Gambas 4.0 version. It is just not
maintained, so I suggest to use gb.args instead.

Regards,

--
Benoît Minisini
»
« Ultima modifica: 17 Ottobre 2012, 13:41:46 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline md9327

  • Moderatore
  • Senatore Gambero
  • *****
  • Post: 2.840
    • Mostra profilo
Re: Aggiunto nuovo componente ''gb.args''
« Risposta #3 il: 17 Ottobre 2012, 13:30:07 »
Bene, provvedo a modificare il codice....  :D

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.287
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Aggiunto nuovo componente ''gb.args''
« Risposta #4 il: 19 Ottobre 2012, 16:09:47 »
Si aggiungono interventi:

« We have some components and libraries that search Application.Args for
an occurrence of a command line arg.  For example one component, our
central db connection manager looks for a "--reconfiguredb" CL option
that allows/forces the user to re-enter the database connection
parameters when we have released a new version of the database.  (So if
we move from auctions030108 to auctions030109 on our central database,
we let them know that they have to run our main app with the
--reconfiguredb option.)

Here's the question.  It would be nice, or to put it another way, is it
possible to declare the Args.Has("","--reconfiguredb", "Reset the
central database connection") in the component or do we have to do it in
any/all the apps that use that component?

regards
Bruce
»


« The current syntax prevents that, because everything is done
between Args.Begin() and Args.End().

Note that you must just collect the result of Args.Has() and Args.Get()
before calling Args.End(). All processing must be done after!

You can:

- Call Args.Has("", "--reconfiguredb") in all projects explicitely.

- Or call it after testing that a specific component is used, with
Component.IsLoaded()

- Or override Args in the component, reimplement Args.End() to add the
Args.Has("", ""--reconfiguredb")

The last solution needs no change in the projects. Only in the components.

Regards,

--
Benoît Minisini
»
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.287
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Aggiunto nuovo componente ''gb.args''
« Risposta #5 il: 28 Ottobre 2012, 23:34:09 »
« Is there a way to deal with application.args to manage special args when gb.args is used ?

Fabien Bodard
 »


« Args.End() will return all arguments that were not interpreted - it assumes that they are file names.

But if you don't want to deal with the syntax implemented by gb.args, the better is not using the component at all.

--
Benoît Minisini
 »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »