File: getopt.lua

package info (click to toggle)
lua-posix 31-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,604 kB
  • ctags: 1,346
  • sloc: sh: 14,309; ansic: 4,794; perl: 76; makefile: 41
file content (26 lines) | stat: -rw-r--r-- 495 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local P = require 'posix'

local short = "ha:s:"

local long = {
  {"help",  "none", 'h'},
  {"aleph", "required", 'a'},
  {"start", "required", 's'}
}

local last_index = 1
for r, optarg, optind, li in P.getopt (arg, short, long) do
  if r == '?' then
    return print  'unrecognized option'
  end
  last_index = optind
  if r == 'h' then
    print 'help'
  elseif r == 'a' or r == 's' then
    print ('we were passed', r, optarg)
  end
end

for i = last_index, #arg do
  print (i, arg[i])
end