-
Notifications
You must be signed in to change notification settings - Fork 2
/
file.go
49 lines (36 loc) · 1.06 KB
/
file.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
49
package main
import (
"errors"
"fmt"
"gopkg.in/alecthomas/kingpin.v2"
)
func setupFileCommand(app *kingpin.Application) {
fileCommand := app.Command("file", "Initialize a new empty file")
fileCommand.Command("init", "Initialize a new empty file").Default()
fileCommand.Command("touch", "Simply load and save the file")
}
func handleFileCommand(commands []string) error {
if len(commands) < 1 {
return errors.New("No subcommand found for file command")
}
switch commands[1] {
case "init":
return handleInitFileCommand(commands)
case "touch":
return handleTouchFileCommand(commands)
default:
return errors.New(fmt.Sprintf("File subcommand not supported : %s", commands[1]))
}
}
func handleInitFileCommand(commands []string) error {
var mealieCryptFile MealieCryptFile
mealieCryptFile.Comment = *comment
return writeFile(filename, true, mealieCryptFile)
}
func handleTouchFileCommand(commands []string) error {
mealieCryptFile, err := readFile(filename, true)
if err != nil {
return err
}
return writeFile(filename, false, mealieCryptFile)
}