diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-20 14:52:59 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-20 14:54:40 -0800 |
| commit | 2bbc035f5dcc3ecd62724b9d1de0e7e3ea902379 (patch) | |
| tree | 34a83497f7570946b6252183b3e8fe0ce2010595 /tools/upgrade.nom | |
| parent | f30413853063483147d941ffccc4b663b71bc943 (diff) | |
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`
Diffstat (limited to 'tools/upgrade.nom')
| -rwxr-xr-x | tools/upgrade.nom | 74 |
1 files changed, 27 insertions, 47 deletions
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 |
