(48 lines)
1 #!/usr/bin/env nomsu -V7.0.02 ###3 Tool to automatically update code from old versions of Nomsu. Usage:4 nomsu tools/upgrade.nom [-i] file1 file2 directory1 ...5 If "-i" is the first argument, upgrades will be performed in-place. Otherwise, the6 upgraded code will be printed.8 use "compatibility"9 use "filesystem"10 use "consolecolor"11 use "commandline"13 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~15 command line program with $args:16 $inplace = ($args.i or $args.inplace)17 $start_version = $args."upgrade-from"18 if $start_version:19 try:20 use $start_version22 $version = ($args."upgrade-to" or $(NOMSU VERSION))23 $test = ($args.t or $args.test)24 for $filename in $args.extras:25 $file = (read file $filename)26 unless $file:27 fail "File does not exist: \$filename"28 $leading_indent = ($file, matching "\n*([ ]*)")29 $code = (NomsuCode from (Source $filename 1 #$file) $file)30 $tree = ($code parsed $start_version)31 $uptree =32 $tree upgraded from ($start_version or ($tree.version or $(NOMSU VERSION))) to33 $version35 $text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")"36 when:37 $inplace:38 say "Upgraded \$filename"39 write $text to file $filename41 $test:42 if ($uptree == $tree):43 say (dim "\$filename will not be changed")44 ..else:45 say (bright "\$filename will be changed")47 else:48 say $text inline