-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (42 loc) · 947 Bytes
/
main.go
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 (
"errors"
"log"
"os"
"github.com/urfave/cli/v2"
)
type ResponseData struct {
IpfsHash string `json:"IpfsHash"`
Slug string `json:"slug"`
}
type UploadPayload struct {
Content string `json:"content"`
Name string `json:"name"`
Lang string `json:"lang"`
}
func main() {
app := &cli.App{
Name: "snip",
Usage: "A CLI for snippets.so, a clean and simple code sharing tool.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Value: "nil",
Usage: "Custom name for snippet. If none provided it will default to the name of the file.",
},
},
Action: func(ctx *cli.Context) error {
filePath := ctx.Args().First()
name := ctx.String("name")
if filePath == "" {
return errors.New("no file path provided")
}
_, err := UploadSnip(filePath, name)
return err
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}