aboutsummaryrefslogtreecommitdiff
path: root/cmd/send-over-http/main.go
blob: 3c587ff19e542bc90c75c546c2f252f9f235e40e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main

import (
	"flag"
	"fmt"
	"os"
	"time"

	sendoverhttp "git.server.ky/cypher/send-over-http"
)

func exitOnErr(err error) {
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(-1)
	}
}

func usage() {
	fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s [target]\n", os.Args[0])
	fmt.Fprintln(flag.CommandLine.Output())
	fmt.Fprintf(flag.CommandLine.Output(), "\ttarget - file or directory to share (default: .)\n")
	fmt.Fprintln(flag.CommandLine.Output())
}

func main() {
	flag.Usage = usage
	flag.Parse()

	var fp string
	if len(os.Args) == 2 {
		fp = os.Args[1]
	}
	if fp == "" {
		v, err := os.Getwd()
		exitOnErr(err)
		fp = v
	}

	s := sendoverhttp.NewServer(fp)
	go s.Start()

	time.Sleep(250 * time.Millisecond)
	fmt.Println("press enter to exit")
	_, _ = fmt.Scanln()

	s.Stop()
}