~kota/pcf

3a2ddad1c5ad53062c63a63467a38b06b527ad22 — Dakota Walsh 3 months ago ea67af1 v2.0.0
implement environment variable configuration

pcf is now configured with an environment variable PCFSERVER. I updated
to readme and man page to explain how to use this variable.
3 files changed, 18 insertions(+), 14 deletions(-)

M README.md
M main.go
M pcf.1.scd
M README.md => README.md +4 -3
@@ 4,9 4,10 @@ pcf
A simple paste.cf command line client. Reads file(s) from STDIN or filename as
argument, uploads to a paste.cf server, and prints the url(s) to STDOUT.

Config files are read to retrieve server information. Optionally server
information can be provided via arguments. See pcf(1) for command line client
information and pcf(5) for config file format information.
The PCFSERVER environment variable is used to declare server information. An
example in your shellrc would be `export
PCFSERVER='https://paste.example.com:21/incoming'`. The port and path are optional
and will depend on how the pcf server you're using is configured.

License
--------

M main.go => main.go +10 -11
@@ 15,13 15,11 @@ import (
	"time"
)

var addr = "https://paste.cf"
var port = "21"
var pub = "incoming"
var addr = os.Getenv("PCFSERVER")

// create the ftp connection
func login(u *url.URL) *ftp.ServerConn {
	c, err := ftp.Dial(u.Host+":"+port, ftp.DialWithTimeout(10*time.Second))
	c, err := ftp.Dial(u.Host, ftp.DialWithTimeout(10*time.Second))
	if err != nil {
		fmt.Fprintf(os.Stderr, "pcf: dial: %v\n", err)
	}


@@ 32,9 30,9 @@ func login(u *url.URL) *ftp.ServerConn {
	return c
}

// store the passed file in the passed connection
func store(f *os.File, c *ftp.ServerConn, n string) {
	err := c.Stor(path.Join(pub, n), f)
// store the file in the connection
func store(u *url.URL, f *os.File, c *ftp.ServerConn, n string) {
	err := c.Stor(path.Join(u.Path, n), f)
	if err != nil {
		fmt.Fprintf(os.Stderr, "pcf: put: %v\n", err)
	}


@@ 55,7 53,7 @@ func put(f *os.File, n string, u *url.URL) {
		os.Exit(1)
	}
	c := login(u)
	store(f, c, n)
	store(u, f, c, n)
	exit(c)
}



@@ 78,14 76,14 @@ func main() {
	if err != nil {
		fmt.Fprintf(os.Stderr, "pcf: url configuration wrong: %v\n", err)
	}
	files := os.Args[1:]
	if len(files) == 0 {
	args := os.Args[1:]
	if len(args) == 0 {
		// use stdin data
		put(os.Stdin, "file", u)
		hash(os.Stdin)
	} else {
		// loop through and use all arguments
		for _, arg := range files {
		for _, arg := range args {
			f, err := os.Open(arg)
			if err != nil {
				fmt.Fprintf(os.Stderr, "pcf: open: %v\n", err)


@@ 98,6 96,7 @@ func main() {
			// calculate the hash
			h := hash(f)
			// print the url
			u.Host = u.Hostname()
			u.Path = h + filepath.Ext(arg)
			fmt.Println(u)
		}

M pcf.1.scd => pcf.1.scd +4 -0
@@ 13,6 13,10 @@ pcf [files]
pcf reads either a list of files as arguments or data from stdin. Then it
uploads it with ftp and prints the resulting url to stdout.

Set the PCFSERVER environment variable for whatever pcf server you'd like to
use. The format looks like PCFSERVER=https://paste.example.com:21/incoming with
the port and path being optional depending on how the ftp server is configured.

# AUTHORS

Maintained by Dakota Walsh <kota at nilsu.org>.