Skip to content

Commit

Permalink
Merge pull request #219 from Igalia/shorten-module-names
Browse files Browse the repository at this point in the history
Shorten module names
  • Loading branch information
wingo committed Feb 4, 2016
2 parents cfd9313 + 606fea6 commit d12e521
Show file tree
Hide file tree
Showing 237 changed files with 42 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ dist: trusty
script:
- make
- sudo make -C src test
- cd src/program/snabb_lwaftr/tests/end-to-end/ && sudo ./end-to-end.sh
- cd src/program/lwaftr/tests/end-to-end/ && sudo ./end-to-end.sh
- sudo ./end-to-end-vlan.sh
60 changes: 29 additions & 31 deletions src/core/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,34 @@ function main ()
zone("startup")
require "lib.lua.strict"
initialize()
local args = parse_command_line()
local program = programname(args[1])
if program == 'snabb' then
-- Print usage with exit status 0 if help requested
if args[2] == '-h' or args[2] == '--help' then
usage(0)
end
-- Print usage with exit status 1 if no arguments supplied
if #args == 1 then
usage(1)
end
-- Strip 'snabb' and use next argument as program name
table.remove(args, 1)
end
program = select_program(program, args)
local program, args = select_program(parse_command_line())
if not lib.have_module(modulename(program)) then
print("unsupported program: "..program:gsub("_", "-"))
print()
print("Rename this executable (cp, mv, ln) to choose a supported program:")
print(" snabb "..(require("programs_inc"):gsub("\n", " ")))
os.exit(1)
usage(1)
else
require(modulename(program)).run(args)
end
end

-- If no more arguments return program as program name
-- If not, use the next argument as program name
function select_program (program, args)
if not args or #args == 0 then return program end
return string.gsub(table.remove(args, 1), "-", "_")
-- Take the program name from the first argument, unless the first
-- argument is "snabb", in which case pop it off, handle any options
-- passed to snabb itself, and use the next argument.
function select_program (args)
local program = programname(table.remove(args, 1))
if program == 'snabb' then
while #args > 0 and args[1]:match('^-') do
local opt = table.remove(args, 1)
if opt == '-h' or opt == '--help' then
usage(0)
else
print("unrecognized option: "..opt)
usage(1)
end
end
if #args == 0 then usage(1) end
program = programname(table.remove(args, 1))
end
return program, args
end

function usage (status)
Expand All @@ -84,6 +81,7 @@ function programname (name)
return name:gsub("^.*/", "")
:gsub("-[0-9.]+[-%w]+$", "")
:gsub("-", "_")
:gsub("^snabb_", "")
end

function modulename (program)
Expand Down Expand Up @@ -132,21 +130,21 @@ function selftest ()
"Incorrect program name parsing")
assert(programname("/bin/snabb-1.0-alpha2") == "snabb",
"Incorrect program name parsing")
assert(programname("/bin/snabb-nfv") == "snabb_nfv",
assert(programname("/bin/snabb-nfv") == "nfv",
"Incorrect program name parsing")
assert(programname("/bin/snabb-nfv-1.0") == "snabb_nfv",
assert(programname("/bin/nfv-1.0") == "nfv",
"Incorrect program name parsing")
assert(modulename("nfv-sync-master-2.0") == "program.nfv_sync_master.nfv_sync_master",
"Incorrect module name parsing")
local pn = programname
-- snabb foo => foo
assert(select_program(pn'snabb', { pn'foo' }) == "foo",
assert(select_program({ 'foo' }) == "foo",
"Incorrect program name selected")
-- snabb-foo => snabb_foo
assert(select_program(pn'snabb-foo', { }) == "snabb_foo",
-- snabb-foo => foo
assert(select_program({ 'snabb-foo' }) == "foo",
"Incorrect program name selected")
-- snabb snabb-foo => snabb_foo
assert(select_program(pn'snabb', { pn'snabb-foo' }) == "snabb_foo",
-- snabb snabb-foo => foo
assert(select_program({ 'snabb', 'snabb-foo' }) == "foo",
"Incorrect program name selected")
end

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ E= @echo
#E= @:

snabb-lwaftr:
$(Q) (cd ../../; make snabb-lwaftr; ln -sf ../../$@ program/snabb_lwaftr/$@)
$(Q) (cd ../../; make snabb-lwaftr; ln -sf ../../$@ program/lwaftr/$@)

snabb-lwaftr-doc: doc/snabb-lwaftr.pdf doc/snabb-lwaftr.html doc/snabb-lwaftr.epub

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local app = require("core.app")
local config = require("core.config")
local lib = require("core.lib")
local csv_stats = require("lib.csv_stats")
local setup = require("program.snabb_lwaftr.setup")
local setup = require("program.lwaftr.setup")

function show_usage(code)
print(require("program.snabb_lwaftr.bench.README_inc"))
print(require("program.lwaftr.bench.README_inc"))
main.exit(code)
end

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module(..., package.seeall)
local app = require("core.app")
local config = require("core.config")
local lib = require("core.lib")
local setup = require("program.snabb_lwaftr.setup")
local setup = require("program.lwaftr.setup")

function show_usage(code)
print(require("program.snabb_lwaftr.check.README_inc"))
print(require("program.lwaftr.check.README_inc"))
main.exit(code)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local stream = require("apps.lwaftr.stream")
local binding_table = require("apps.lwaftr.binding_table")

function show_usage(code)
print(require("program.snabb_lwaftr.compile_binding_table.README_inc"))
print(require("program.lwaftr.compile_binding_table.README_inc"))
main.exit(code)
end

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module(..., package.seeall)
local lib = require("core.lib")

local function show_usage(exit_code)
print(require("program.snabb_lwaftr.README_inc"))
print(require("program.lwaftr.README_inc"))
main.exit(exit_code)
end

function run(args)
if #args == 0 then show_usage(1) end
local command = string.gsub(table.remove(args, 1), "-", "_")
local modname = ("program.snabb_lwaftr.%s.%s"):format(command, command)
local modname = ("program.lwaftr.%s.%s"):format(command, command)
if not lib.have_module(modname) then
show_usage(1)
end
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ local S = require("syscall")
local config = require("core.config")
local csv_stats = require("lib.csv_stats")
local lib = require("core.lib")
local setup = require("program.snabb_lwaftr.setup")
local setup = require("program.lwaftr.setup")

local function show_usage(exit_code)
print(require("program.snabb_lwaftr.run.README_inc"))
print(require("program.lwaftr.run.README_inc"))
if exit_code then main.exit(exit_code) end
end

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ local function parse_args(args)
inet_if = arg
end;
h = function (arg)
print(require("program.snabb_lwaftr.run_nohw.README_inc"))
print(require("program.lwaftr.run_nohw.README_inc"))
main.exit(0)
end;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local lib = require("core.lib")
local ffi = require("ffi")

function show_usage(code)
print(require("program.snabb_lwaftr.transient.README_inc"))
print(require("program.lwaftr.transient.README_inc"))
main.exit(code)
end

Expand Down

0 comments on commit d12e521

Please sign in to comment.