[RFC] Some options should be 'common', not 'global'

Jari Aalto jari.aalto at cante.net
Mon Aug 27 15:57:29 BST 2007


Ian Clatworthy <ian.clatworthy at internode.on.net> writes:

>>     --verbose [LEVEL]
>>     --quiet [LEVEL]
>> 
>> where these would be equivalent. The level 10 is imaginary maximum
>> level, program may choose to implement only 3, but allow naturally
>> higher numbers.
> [snip]
>> That is, repeated options increase the effect, examples:
>> 
>>     --verbose --verbose (or -v -v, -vv)  <=> --verbose 2
>>     --quiet --quiet (or -q -q, -qq)  <=> --quiet 2
>
> Your suggestion is an interesting one. It does feel more complex though
> than simply having 3 levels and using those wisely across the product.
> Can you think of a command within bzr that really needs more than 3 levels?

I was more tinking about the implementation. If you implement levels,
that should generic. An example pseudo code:

    function debug (message &optional level)
    {
        if level => global level
           write that message
    }

    function doWork ()
    {
        Debug("One");
        
        for var in loop
        {
            Debug("value of VAR", 2);

            if case
                Debug("Special case!", 3);
        }
    }

That's pretty much standard as what I know how the levels are handled.
Program may choose to use up to N, but the implmentation support as
high as needed.

> Likewise, I like the fact that -q means a certain thing - nothing except
> errors and warnings - and scripts can rely on that. If -q simply means
> 'one level less verbosity than current', then it's not predictable in
> scripts. I appreciate that having LEVEL as an optional parameter means
> scripts could do -q0 to achieve that, of course.

I think it's reasonable to think

    -q      simply mean quiet (zero output, except fatal errors)

but that could as easily be treated like this:

    - Programs starts. The default verbose is set to 3 at boot.
      I.e. somthing that's considered "normal".
    - If used passed "--verbose 2", change it to 2.
    - If user passed "-q", decrease it by 1 further.

The end result from program's point of view:

    verbose = 3
    ... deal with options
    verbose = 1
    ... and display only messages at that level

You couls also allow symbolic names if you go fancy:

    --verbose none          <=> 0
    --verbose normal        <=> 3
    --verbose max           <=> 5 , or why not bump straight to 10
 
> I could be wrong but I don't think we have any options right now with
> optional arguments. In other words, the LEVEL would currently always
> have to be provided? I don't know whether that's because we simply
> haven't added them.

Hm. I've used optional arguments many times on other programs (Perl is
famous of them in Getopt::Long.pm). 

Jari




More information about the bazaar mailing list