|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + |
| 6 | + "gopkg.in/alecthomas/kingpin.v2" |
| 7 | + "limbo.services/version" |
| 8 | +) |
| 9 | + |
| 10 | +func main() { |
| 11 | + var ( |
| 12 | + configFile string |
| 13 | + receiverName string |
| 14 | + receiverKey string |
| 15 | + ) |
| 16 | + |
| 17 | + app := kingpin.New("sec", "Simple secure data"). |
| 18 | + Version(version.Get().String()). |
| 19 | + Author(version.Get().ReleasedBy) |
| 20 | + |
| 21 | + initCmd := app.Command("init", "Initialize a config file") |
| 22 | + initCmd.Flag("config", "path to the config file").Short('c'). |
| 23 | + Default("./sec-config.json").PlaceHolder("FILE").Envar("SEC_CONFIG"). |
| 24 | + StringVar(&configFile) |
| 25 | + |
| 26 | + configCmd := app.Command("config", "Show the content of a config file") |
| 27 | + configCmd.Flag("config", "path to the config file").Short('c'). |
| 28 | + Default("./sec-config.json").PlaceHolder("FILE").Envar("SEC_CONFIG"). |
| 29 | + ExistingFileVar(&configFile) |
| 30 | + |
| 31 | + receiverAddCmd := app.Command("receiver-add", "Register a new receiver") |
| 32 | + receiverAddCmd.Arg("name", "name of the receiver").Required(). |
| 33 | + StringVar(&receiverName) |
| 34 | + receiverAddCmd.Flag("config", "path to the config file").Short('c'). |
| 35 | + Default("./sec-config.json").PlaceHolder("FILE").Envar("SEC_CONFIG"). |
| 36 | + ExistingFileVar(&configFile) |
| 37 | + |
| 38 | + receiverRemoveCmd := app.Command("receiver-remove", "Remove a receiver") |
| 39 | + receiverRemoveCmd.Arg("name", "name of the receiver").Required(). |
| 40 | + StringVar(&receiverName) |
| 41 | + receiverRemoveCmd.Flag("config", "path to the config file").Short('c'). |
| 42 | + Default("./sec-config.json").PlaceHolder("FILE").Envar("SEC_CONFIG"). |
| 43 | + ExistingFileVar(&configFile) |
| 44 | + |
| 45 | + encCmd := app.Command("enc", "Encrypt data from STDIN") |
| 46 | + encCmd.Flag("config", "path to the config file").Short('c'). |
| 47 | + Default("./sec-config.json").PlaceHolder("FILE").Envar("SEC_CONFIG"). |
| 48 | + ExistingFileVar(&configFile) |
| 49 | + |
| 50 | + decCmd := app.Command("dec", "Decrypt data from STDIN") |
| 51 | + decCmd.Flag("key", "receiver key").Short('k'). |
| 52 | + PlaceHolder("KEY").Envar("SEC_KEY"). |
| 53 | + Required().StringVar(&receiverKey) |
| 54 | + |
| 55 | + switch kingpin.MustParse(app.Parse(os.Args[1:])) { |
| 56 | + case initCmd.FullCommand(): |
| 57 | + doInit(app, configFile) |
| 58 | + case configCmd.FullCommand(): |
| 59 | + config(app, configFile) |
| 60 | + case receiverAddCmd.FullCommand(): |
| 61 | + receiverAdd(app, configFile, receiverName) |
| 62 | + case receiverRemoveCmd.FullCommand(): |
| 63 | + receiverRemove(app, configFile, receiverName) |
| 64 | + case encCmd.FullCommand(): |
| 65 | + enc(app, configFile) |
| 66 | + case decCmd.FullCommand(): |
| 67 | + dec(app, receiverKey) |
| 68 | + } |
| 69 | +} |
0 commit comments