~henesy/runez2

98adfdfacd54c540751e4062e581143576e5344a — henesy 1 year, 12 days ago 1fa09aa master
allow runez2 to use in/out files as arguments
2 files changed, 32 insertions(+), 3 deletions(-)

M README.md
M main.go
M README.md => README.md +1 -1
@@ 12,7 12,7 @@ See [the spec](./spec.md) for implementation details, or read the source ☺.

## Usage

	runez2 [-D] [-c | -d] < input > output
	runez2 [-D] [-c ¦ -d] [input ¦ < input] [output ¦ > output]

## Examples


M main.go => main.go +31 -2
@@ 35,9 35,38 @@ func main() {
	}

	// TODO - allow calling like `runez2 -c foo.txt` ;; use flag.Args
	inf := os.Stdin
	outf := os.Stdout

	args := flag.Args()
	switch len(args) {
	case 0:
	case 1:
		f, err := os.OpenFile(args[0], os.O_RDONLY, 0755)
		if err != nil {
			fatal("err: could not read input file - ", err)
		}

		inf = f
	case 2:
		fin, err := os.OpenFile(args[0], os.O_RDONLY, 0755)
		if err != nil {
			fatal("err: could not read input file - ", err)
		}

		fout, err := os.OpenFile(args[1], os.O_RDWR|os.O_CREATE, 0755)
		if err != nil {
			fatal("err: could not read input file - ", err)
		}

		inf = fin
		outf = fout
	default:
		fatal("err: invalid argument count; use stdin/stdout or specify in/out files")
	}

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	in := bufio.NewReader(inf)
	out := bufio.NewWriter(outf)

	// Choose mode operation
	switch {