aboutsummaryrefslogtreecommitdiff
path: root/tools/upgrade.nom
blob: 781e71bad07eeca7750530034f7c1d2c72cfb85b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env nomsu -V4.11.12.8
#
    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 "lib/os.nom"
use "lib/consolecolor.nom"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%args = (command line 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.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
        
        %test:
            if (%uptree == %tree):
                say (dim "\%filename will not be changed")
            ..else:
                say (bright "\%filename will be changed")
        
        else:
            say %text inline