From 2bbc035f5dcc3ecd62724b9d1de0e7e3ea902379 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 20 Nov 2018 14:52:59 -0800 Subject: Simplifying the filesystem code (no longer entangled with nomsupath) and using that to simplify the tools. Now the tools directly take lists of file paths rather than things that might go through nomsupath or directories or get processed by filetype. Use your shell for globbing stuff like `nomsu tools/test.nom core/*.nom` --- tools/upgrade.nom | 74 ++++++++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) (limited to 'tools/upgrade.nom') diff --git a/tools/upgrade.nom b/tools/upgrade.nom index 56d67a5..781e71b 100755 --- a/tools/upgrade.nom +++ b/tools/upgrade.nom @@ -7,56 +7,36 @@ use "compatibility" use "lib/os.nom" +use "lib/consolecolor.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %args = (command line args) -%inplace = (no) -%start_version = (nil) -%version = (Nomsu version) -repeat: - if %args.1 is: - "-i": - %inplace = (yes) - %args::remove index 1 +%inplace = (%args."-i" or %args."--inplace") +%start_version = %args."--upgrade-from" +%version = (%args."--upgrade-to" or (Nomsu version)) +%test = (%args."-t" or %args."--test") +for %filename in %args.extra_args: + %file = (read file %filename) + unless %file: + barf "File does not exist: \%filename" + %leading_indent = (%file::matching "[\n]*([ ]*)") + %code = (NomsuCode from (Source %filename 1 (size of %file)) %file) + %tree = (%code parsed) + %uptree = (..) + %tree upgraded from (%start_version or (%tree.version or (Nomsu version))) to \ + ..%version + %text = "\%leading_indent\(((%uptree as nomsu)::text)::with "\n" -> "\n\%leading_indent")" + when: + %inplace: + say "Upgraded \%filename" + write %text to file %filename - "-t": - use "lib/consolecolor.nom" - %test = (yes) - %args::remove index 1 + %test: + if (%uptree == %tree): + say (dim "\%filename will not be changed") + ..else: + say (bright "\%filename will be changed") - "-V": - %version = %args.2 - %args::remove index 1 - %args::remove index 1 - - "-S": - %start_version = %args.2 - %args::remove index 1 - %args::remove index 1 - - else: stop - -for %path in %args: - for %filename in (files for %path): - unless (%filename::matches "%.nom$"): do next %filename - %file = (read file %filename) - %code = (NomsuCode from (%Source %filename 1 (size of %file)) %file) - %tree = (%code parsed) - %uptree = (..) - %tree upgraded from (%start_version or (%tree.version or (Nomsu version))) to \ - ..%version - %text = ((%uptree as nomsu)::text) - when: - %inplace: - say "Upgraded \%filename" - write %text to file %filename - - %test: - if (%uptree == %tree): - say (dim "\%filename will not be changed") - ..else: - say (bright "\%filename will be changed") - - else: - say %text + else: + say %text inline -- cgit v1.2.3