149 lines
3.1 KiB
Go
149 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"gitea.benny.dog/torjus/ezshare/actions"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
const Version = "v0.1.1"
|
|
|
|
func main() {
|
|
cli.VersionFlag = &cli.BoolFlag{Name: "version"}
|
|
app := cli.App{
|
|
Name: "ezshare",
|
|
Version: 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]..",
|
|
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: "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)
|
|
}
|
|
|
|
}
|