package app import ( "database/sql" "errors" "fmt" "time" appconfig "gitocean/internal/config" "gitocean/internal/model" "gitocean/internal/validate" ) const ( defaultServerURL = appconfig.DefaultServerURL defaultStorage = appconfig.DefaultStorage tokenTTL = 7 * 24 * time.Hour ) var ( ErrUsage = errors.New("usage") usernameRE = validate.UsernameRE repoNameRE = validate.RepoNameRE branchRE = validate.BranchRE ) type User = model.User type Repository = model.Repository type PullRequest = model.PullRequest type ServerConfig = model.ServerConfig type RefInfo = model.RefInfo type Collaborator = model.Collaborator type PRComment = model.PRComment type TokenInfo = model.TokenInfo type Config = model.Config type Server struct { db *sql.DB storage string publicURL string } func Run(args []string) error { if len(args) < 1 { usage() return ErrUsage } switch args[0] { case "init": return cliInit(args[1:]) case "server": return runServer(args[1:]) case "register": return cliRegister(args[1:]) case "login": return cliLogin(args[1:]) case "logout": return cliLogout(args[1:]) case "whoami": return cliWhoami(args[1:]) case "clone": return cliClone(args[1:]) case "repo": return cliRepo(args[1:]) case "pr": return cliPR(args[1:]) case "token": return cliToken(args[1:]) case "admin": return cliAdmin(args[1:]) case "backup": return cliBackup(args[1:]) case "help", "-h", "--help": usage() return nil default: return fmt.Errorf("unknown command %q", args[0]) } } func usage() { fmt.Println(`gitocean - CLI and server for a small Git hosting platform Commands: gitocean init [--config storage/config.json] gitocean server [--config storage/config.json] [--dsn DSN] [--addr :8080] [--storage storage] gitocean server users --dsn DSN list gitocean server users --dsn DSN view USER gitocean server users --dsn DSN add --email EMAIL --username USER --password PASSWORD [--admin] gitocean server users --dsn DSN edit USER [--email EMAIL] [--username USER] [--password PASSWORD] [--admin true|false] gitocean server users --dsn DSN remove USER --force gitocean register [--server URL] gitocean login [--server URL] gitocean logout gitocean whoami gitocean clone OWNER/REPO gitocean repo create NAME (--public|--private) [--description TEXT] gitocean repo publish NAME (--public|--private) [--remote origin] [--branch main] gitocean repo view OWNER/REPO gitocean repo branches OWNER/REPO gitocean repo tags OWNER/REPO gitocean repo set OWNER/REPO [--description TEXT] [--visibility public|private] [--default-branch main] gitocean repo delete OWNER/REPO [--force] gitocean repo search QUERY [--all|--mine] [--json] gitocean repo fork OWNER/REPO [--name NEW_NAME] gitocean repo collaborators OWNER/REPO gitocean repo collaborator add OWNER/REPO USER --role read|write gitocean repo collaborator remove OWNER/REPO USER gitocean pr create --from OWNER/REPO:BRANCH --to OWNER/REPO:BRANCH --title TITLE [--description DESC] gitocean pr create --repo OWNER/REPO --from BRANCH --to BRANCH --title TITLE [--description DESC] gitocean pr list OWNER/REPO [--json] gitocean pr view OWNER/REPO NUMBER [--json] gitocean pr diff OWNER/REPO NUMBER gitocean pr checkout OWNER/REPO NUMBER gitocean pr comment OWNER/REPO NUMBER "text" gitocean pr comments OWNER/REPO NUMBER gitocean pr close OWNER/REPO NUMBER gitocean pr merge OWNER/REPO NUMBER gitocean token list [--json] gitocean token revoke TOKEN_ID gitocean token prune gitocean admin users list gitocean admin users delete USER gitocean admin repos list gitocean admin storage check gitocean backup create FILE gitocean backup restore FILE`) }