ezshare/main.go
2021-12-08 05:42:25 +01:00

202 lines
4.5 KiB
Go

package main
import (
"log"
"os"
"gitea.benny.dog/torjus/ezshare/actions"
"gitea.benny.dog/torjus/ezshare/ezshare"
"github.com/urfave/cli/v2"
)
func main() {
cli.VersionFlag = &cli.BoolFlag{Name: "version"}
app := cli.App{
Name: "ezshare",
Version: ezshare.Version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Usage: "Path to config-file.",
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Usage: "Be more verbose",
},
},
Commands: []*cli.Command{
{
Name: "serve",
Usage: "Start ezshare server",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "no-grpc",
Usage: "Do not enable grpc.",
},
&cli.BoolFlag{
Name: "no-http",
Usage: "Do not enable http.",
},
&cli.StringFlag{
Name: "grpc-addr",
Usage: "Address to listen for grpc.",
},
&cli.StringFlag{
Name: "http-addr",
Usage: "Address to listen for http.",
},
&cli.StringFlag{
Name: "hostname",
Usage: "Hostname used in links",
},
},
Action: actions.ActionServe,
},
{
Name: "client",
Usage: "Client commands",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "addr",
Usage: "Address of server.",
},
},
Subcommands: []*cli.Command{
{
Name: "get",
Usage: "Get file with id",
ArgsUsage: "ID [ID]..",
Action: actions.ActionClientGet,
},
{
Name: "upload",
Usage: "Upload file(s)",
ArgsUsage: "PATH [PATH]..",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "with-passcode",
Usage: "Require passcode to view",
},
&cli.DurationFlag{
Name: "ttl",
Usage: "Expire file when duration has passed",
},
&cli.IntFlag{
Name: "max-views",
Usage: "Limit the amount of times the file can be viewed.",
},
},
Action: actions.ActionClientUpload,
},
{
Name: "delete",
Usage: "Delete file with id",
ArgsUsage: "ID [ID]..",
Action: actions.ActionClientDelete,
},
{
Name: "list",
Usage: "List files",
Action: actions.ActionClientList,
},
{
Name: "login",
Usage: "Login and retrieve client cert",
ArgsUsage: "[PROTO://]HOSTNAME[:PORT]",
Action: actions.ActionClientLogin,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "username",
Usage: "Username used for login.",
},
&cli.BoolFlag{
Name: "overwrite",
Usage: "Overwrite existing config",
},
},
},
{
Name: "change-password",
Usage: "Change password",
Action: actions.ActionClientChangePassword,
},
{
// TODO: Remove
Name: "config-init",
Usage: "Initialize default config",
Action: actions.ActionInitConfig,
},
{
Name: "update",
Usage: "Download the latest ezshare",
Action: actions.ActionClientUpdate,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "out-dir",
Usage: "Directory where binary is saved",
},
},
},
{
Name: "cert",
Usage: "Certificate-related commands",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "List certificates",
Action: actions.ActionClientCertList,
},
{
Name: "revoke",
Usage: "Revoke certificate(s)",
ArgsUsage: "SERIAL [SERIAL...]",
Action: actions.ActionClientCertRevoke,
},
},
},
},
},
{
Name: "admin",
Usage: "Admin commands",
Subcommands: []*cli.Command{
{
Name: "upload",
Usage: "Upload binaries to be served",
ArgsUsage: "FILENAME [FILENAME...]",
Action: actions.ActionAdminUploadBinary,
},
},
},
{
Name: "cert",
Usage: "Certificate commands",
Subcommands: []*cli.Command{
{
Name: "gen-all",
Usage: "Generate CA, Server and Client certificates",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "out-dir",
Usage: "Directory where certificates will be stored.",
},
&cli.StringFlag{
Name: "hostname",
Usage: "Hostname used for server certificate.",
},
},
Action: actions.ActionGencerts,
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Printf("Error: %s\n", err)
}
}