diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-20 14:52:59 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-20 14:54:40 -0800 |
| commit | 2bbc035f5dcc3ecd62724b9d1de0e7e3ea902379 (patch) | |
| tree | 34a83497f7570946b6252183b3e8fe0ce2010595 /tools/autoformat.nom | |
| parent | f30413853063483147d941ffccc4b663b71bc943 (diff) | |
Simplifying the filesystem code (no longer entangled with nomsupath) and
using that to simplify the tools. Now the tools directly take lists of
file paths rather than things that might go through nomsupath or
directories or get processed by filetype. Use your shell for globbing stuff like
`nomsu tools/test.nom core/*.nom`
Diffstat (limited to 'tools/autoformat.nom')
| -rwxr-xr-x | tools/autoformat.nom | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/tools/autoformat.nom b/tools/autoformat.nom index 96b732b..5661145 100755 --- a/tools/autoformat.nom +++ b/tools/autoformat.nom @@ -10,23 +10,17 @@ use "lib/os.nom" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ %args = (command line args) -%inplace = (no) -if (%args.1 is "-i"): - %inplace = (yes) - %args::remove index 1 - -for %path in %args: - if (%path == "-"): - %path = "stdin" +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) + %formatted = "\ + ..\%leading_indent\(((%tree as nomsu)::text)::with "\n" -> "\n\%leading_indent")" - for %filename in (files for %path): - unless ((%filename::matches "%.nom$") or (%filename == "stdin")): - do next %filename - %contents = (read file %filename) - %code = (NomsuCode from (Source %filename 1 (size of %contents)) %contents) - %tree = (%code parsed) - %formatted = ((%tree as nomsu)::text) - if %inplace: - write %formatted to file %filename - ..else: - say %formatted inline + if %args."-i": + write %formatted to file %filename + ..else: + say %formatted inline |
