aboutsummaryrefslogtreecommitdiff
path: root/tools/upgrade.nom
blob: 4975aad7c69ac0ea16ff66e012b0080654c38d30 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env nomsu -V4.8.10
#
    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"

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

%args = (command line args)
%inplace = (no)
%start_version = (nil)
%version = (Nomsu version)
repeat:
    if %args.1 is:
        "-i":
            %inplace = (yes)
            %args::remove index 1
        
        "-t":
            use "lib/consolecolor.nom"
            %test = (yes)
            %args::remove index 1
        
        "-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 file %filename in %path:
        unless (%filename::matches "%.nom$"): do next %filename
        %tree = (parse (read file %filename) from %filename)
        %uptree = (..)
            %tree upgraded from (%start_version or (%tree.version or (Nomsu version))) to %version
        %text = "\
            ..#!/usr/bin/env nomsu -V\%version
            \(%uptree as nomsu)"
        
        if:
            %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