From 94740a9b414a0fd9af70acb9b8bf3b9576b537e1 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 18 Dec 2018 19:23:20 -0800 Subject: Improved command line interface and robustness of tools. --- tools/autoformat.nom | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'tools/autoformat.nom') 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 -- cgit v1.2.3