diff options
Diffstat (limited to 'tools/autoformat.nom')
| -rwxr-xr-x | tools/autoformat.nom | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/tools/autoformat.nom b/tools/autoformat.nom index 76d1d27..d878a02 100755 --- a/tools/autoformat.nom +++ b/tools/autoformat.nom @@ -1,16 +1,21 @@ #!/usr/bin/env nomsu -V5.12.12.8 # Auto-format Nomsu code. Usage: - nomsu tools/autoformat.nom [-i] file1 file2 directory1 ... - If the first argument is "-i", modifications will be performed in-place. Otherwise, - the formatted code will be printed. + nomsu -t autoformat [-i] file1 file2... + + If the "-i" flag is used, the file will be edited in-place. + If no files are passed in, this will read from stdin. use "lib/os.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -$args = (command line args) -for $filename in $args.extra_args: +$filenames = $(COMMAND LINE ARGS).extras +if ((#$filenames) == 0): + say "Warning: reading from stdin (ctrl-d to abort). To avoid this message, use nomsu -t autoformat -" + $filenames = ["stdin"] + +for $filename in $filenames: $file = (read file $filename) unless $file: barf "File does not exist: \$filename" @@ -20,7 +25,7 @@ for $filename in $args.extra_args: $formatted = " \$leading_indent\((($tree as nomsu)|text)|with "\n" -> "\n\$leading_indent")" - if $args."-i": + if $(COMMAND LINE ARGS)."-i": write $formatted to file $filename ..else: say $formatted inline |
