Tcl Library Source Code

View Ticket
Login
Ticket UUID: 422bc67f03ad9e7d374506c1a4ef88f7004f495a
Title: Tcllib cmdline example is inadequate
Type: Bug Version:
Submitter: anonymous Created on: 2020-09-17 09:16:37
Subsystem: cmdline Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Open Last Modified: 2021-03-26 10:35:16
Resolution: None Closed By: nobody
    Closed on:
Description:
The command line example doesn't show the most basic use of a command line:

myapp -opt1 value1 -flag2 *.txt

Instead it only shows how to handle options, but not files.

I have tried using, e.g., cmdline::getfiles *.zip false for these command lines:
myapp -l /tmp/a.zip
myapp /tmp/a.zip
where /tmp/a.zip exists, and in both cases getfiles says there are not matching files.
User Comments: aku added on 2021-03-26 10:35:16:
Another question for [email protected] ...

What platform do you use cmdline on ?

   Windows ?
   Or Unix ?

I ask because the documentation of the `getfiles`
states:

    On Windows, file globbing is performed on each argument.

    On Unix, only file existence is tested.

    If a file argument produces no valid files, a warning is optionally
    generated (set [arg quiet] to true).

I suspect/speculate that the difference comes from the original authors of the package expecting that a shell performs glob matching and expansion before `getfiles` see the words.

aku added on 2021-03-26 10:30:49:

Hello anonymous. With regard to

<quote> I found issue with this optind variable missing (not global ?) </quote>

I am unable to find an optind variable in the entirety of the package. There is nothing defined/used in the code, nor documented.

Checking further, there is no such thing in the entirety of Tcllib.

Can you tell me where you found documentation indicating that it should exist ?


anonymous added on 2021-03-25 16:38:47:
I am agree, and the example do not show use of  ::cmdline:getopt which is also necessary if we managed several call of an option (ex: myapp -i <val1> -i <val2>. 
I found issue with this optind variable missing (not global ?)
package require cmdline
while { [ set err [ ::cmdline::getopt argv "agu" opt arg ]] } {
  puts stderr "salut $err:$opt $arg"
  if { $err < 0 } then {
    puts stderr "$argv0: $arg"
    usage
  } else {
    switch -exact $opt {
      a {
        puts "help"
        usage
      }
      g {
        set debug 1
      }
      u {
        set user $optarg
      }
    }
  }
}

set argv [ lrange $argv $::optind end ]

puts -nonewline stdout "The rest of the arguments are: "
set prefix ""
foreach arg $argv {
  puts -nonewline stdout "$prefix
  set prefix ", "
}
puts stdout ""

But I am a new tcl/expect user.

anonymous added on 2021-03-25 16:38:45:
I am agree, and the example do not show use of  ::cmdline:getopt which is also necessary if we managed several call of an option (ex: myapp -i <val1> -i <val2>. 
I found issue with this optind variable missing (not global ?)
package require cmdline
while { [ set err [ ::cmdline::getopt argv "agu" opt arg ]] } {
  puts stderr "salut $err:$opt $arg"
  if { $err < 0 } then {
    puts stderr "$argv0: $arg"
    usage
  } else {
    switch -exact $opt {
      a {
        puts "help"
        usage
      }
      g {
        set debug 1
      }
      u {
        set user $optarg
      }
    }
  }
}

set argv [ lrange $argv $::optind end ]

puts -nonewline stdout "The rest of the arguments are: "
set prefix ""
foreach arg $argv {
  puts -nonewline stdout "$prefix
  set prefix ", "
}
puts stdout ""

But I am a new tcl/expect user.

aku added on 2021-03-02 21:22:46:
Am I going correctly with the assumption that `myapp` is your script, and uses `getfiles` internally ?
Does it use any of the other cmdline commands ?

If yes, then the shell from which you invoke `myapp` should have expanded the *.txt into a series of paths given to `myapp` as separate arguments.

Is it possible for you to give us a form of your `myapp` script reduced to the essentials of the command line processing in it ?