aboutsummaryrefslogtreecommitdiff
path: root/tools/autoformat.nom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-12-18 19:23:20 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-12-18 19:24:37 -0800
commit94740a9b414a0fd9af70acb9b8bf3b9576b537e1 (patch)
treed0b18232b285d3f5216dce195fb06b6f3685b070 /tools/autoformat.nom
parentad09f002e84d0e317c9563784b829f6f0102e994 (diff)
Improved command line interface and robustness of tools.
Diffstat (limited to 'tools/autoformat.nom')
-rwxr-xr-xtools/autoformat.nom17
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