From: Jean Privat Date: Tue, 22 Apr 2014 19:53:02 +0000 (-0400) Subject: nitls: add option --path to force the output of paths only X-Git-Tag: v0.6.6~104^2~5 X-Git-Url: http://nitlanguage.org nitls: add option --path to force the output of paths only Otherwise, a couple `name (filepath)` is displayed for each entry Signed-off-by: Jean Privat --- diff --git a/Makefile b/Makefile index da446f9..a88d277 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ doc/stdlib/index.html: bin/nitdoc bin/nitls @echo '***************************************************************' @echo '* Generate doc for NIT standard library *' @echo '***************************************************************' - bin/nitdoc $$(bin/nitls lib -r) -d doc/stdlib \ + bin/nitdoc $$(bin/nitls lib -r --path) -d doc/stdlib \ --custom-title "Nit Standard Library" \ --custom-menu-items "
  • Nitlanguage.org
  • " \ --custom-overview-text "

    Documentation for the standard library of Nit
    Version $$(git describe)
    Date: $$(git show --format="%cd" | head -1)

    " \ diff --git a/src/nitls.nit b/src/nitls.nit index 3c24c20..b1598ac 100644 --- a/src/nitls.nit +++ b/src/nitls.nit @@ -20,6 +20,31 @@ module nitls intrude import modelbuilder import ordered_tree +class ProjTree + super OrderedTree[Object] + + var opt_paths = false + + redef fun display(o) + do + if o isa MGroup then + if opt_paths then + return o.filepath.as(not null) + else + return "{o.name} ({o.filepath})" + end + else if o isa ModulePath then + if opt_paths then + return o.filepath + else + return "{o.name} ({o.filepath})" + end + else + abort + end + end +end + var tc = new ToolContext var model = new Model var mb = new ModelBuilder(model, tc) @@ -30,8 +55,9 @@ var opt_tree = new OptionBool("List source files in their groups and projects", var opt_source = new OptionBool("List source files", "-s", "--source") var opt_project = new OptionBool("List projects paths (default)", "-p", "--project") var opt_depends = new OptionBool("List dependencies of given modules", "-M", "--depends") +var opt_paths = new OptionBool("List only path (instead of name + path)", "-p", "--path") -tc.option_context.add_option(opt_keep, opt_recursive, opt_tree, opt_source, opt_project, opt_depends) +tc.option_context.add_option(opt_keep, opt_recursive, opt_tree, opt_source, opt_project, opt_depends, opt_paths) tc.tooldescription = "Usage: nitls [OPTION]... ...\nLists the projects and/or paths of Nit sources files." tc.process_options(args) @@ -83,7 +109,8 @@ for a in files do end if opt_tree.value then - var ot = new OrderedTree[Object] + var ot = new ProjTree + ot.opt_paths = opt_paths.value for p in model.mprojects do for g in p.mgroups do ot.add(g.parent, g) @@ -101,7 +128,11 @@ if opt_source.value then for p in model.mprojects do for g in p.mgroups do for mp in g.module_paths do - list.add(mp.filepath) + if opt_paths.value then + list.add(mp.filepath) + else + list.add("{g.full_name}/{mp.name} ({mp.filepath})") + end end end end @@ -112,7 +143,12 @@ end if opt_project.value then var list = new Array[String] for p in model.mprojects do - list.add(p.root.filepath.as(not null)) + var path = p.root.filepath.as(not null) + if opt_paths.value then + list.add(path) + else + list.add("{p.name} ({path})") + end end alpha_comparator.sort(list) for l in list do print l