diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-14 15:42:48 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-14 15:43:24 -0800 |
| commit | c1c32688a4afc43f6addb99b8b5fa878944a70e3 (patch) | |
| tree | c886f21b5b08a9053aa74fcba4b241dae5ede76d /lib/tools/upgrade.nom | |
| parent | 2309b696fc34b24f05f6658b94f9105ca8ee76e4 (diff) | |
Overhaul in progress, mostly working. Moved all the nomsu packages into
lib/, including core/*. Changes to how nomsu environments and importing
work.
Diffstat (limited to 'lib/tools/upgrade.nom')
| -rwxr-xr-x | lib/tools/upgrade.nom | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/tools/upgrade.nom b/lib/tools/upgrade.nom new file mode 100755 index 0000000..1ef91b9 --- /dev/null +++ b/lib/tools/upgrade.nom @@ -0,0 +1,43 @@ +#!/usr/bin/env nomsu -V6.14 +# + Tool to automatically update code from old versions of Nomsu. Usage: + nomsu tools/upgrade.nom [-i] file1 file2 directory1 ... + If "-i" is the first argument, upgrades will be performed in-place. Otherwise, the + upgraded code will be printed. + +use "compatibility" +use "filesystem" +use "consolecolor" +use "commandline" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +command line program with $args: + $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.extras: + $file = (read file $filename) + unless $file: + fail "File does not exist: \$filename" + $leading_indent = ($file, matching "\n*([ ]*)") + $code = (NomsuCode from (Source $filename 1 (size of $file)) $file) + $tree = ($code parsed $start_version) + $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 + + $test: + if ($uptree == $tree): + say (dim "\$filename will not be changed") + ..else: + say (bright "\$filename will be changed") + + else: + say $text inline |
