~kota/pcf

0fbb7913e282924c30919f10fc18dddd950ff00e — Dakota Walsh 2 years ago a88c359
implement file reading from args or stdin
1 files changed, 30 insertions(+), 2 deletions(-)

M main.go
M main.go => main.go +30 -2
@@ 1,10 1,38 @@
// pcf - A simple paste.cf command line client
// pcf - A powerful paste.cf command line client
// Copyright (C) 2019 Dakota Walsh
// GPL3+ See LICENSE in this repo for details.
package main

import (
	"bufio"
	"fmt"
	"os"
)

// var addr = "paste.cf"
// var pub = "incoming"
// var max = 10 * 1024 * 1024
func upload(f *os.File) {
	input := bufio.NewScanner(f)
	for input.Scan() {
		fmt.Println(input.Text())
	}
}

func main() {
	fmt.Println("hello world")
	files := os.Args[1:]
	if len(files) == 0 {
		upload(os.Stdin)
	} else {
		for _, arg := range files {
			f, err := os.Open(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr, "pcf: %v\n", err)
				continue
			}
			upload(f)
			f.Close()
		}
	}
	fmt.Println("Done")
}