2020-12-16 17:18:10 +01:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2018-09-03 08:43:00 +02:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Tea is command line tool for Gitea.
|
|
|
|
package main // import "code.gitea.io/tea"
|
|
|
|
|
|
|
|
import (
|
2020-12-16 17:18:10 +01:00
|
|
|
"fmt"
|
2018-09-03 08:43:00 +02:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"code.gitea.io/tea/cmd"
|
|
|
|
|
2020-01-04 18:44:25 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 08:43:00 +02:00
|
|
|
)
|
|
|
|
|
2020-04-22 21:11:03 +02:00
|
|
|
// Version holds the current tea version
|
|
|
|
var Version = "development"
|
2018-09-03 08:43:00 +02:00
|
|
|
|
|
|
|
// Tags holds the build tags used
|
|
|
|
var Tags = ""
|
|
|
|
|
|
|
|
func main() {
|
2020-12-21 14:37:20 +01:00
|
|
|
// make parsing tea --version easier, by printing /just/ the version string
|
|
|
|
cli.VersionPrinter = func(c *cli.Context) { fmt.Fprintln(c.App.Writer, c.App.Version) }
|
|
|
|
|
2018-09-03 08:43:00 +02:00
|
|
|
app := cli.NewApp()
|
2020-03-06 04:43:28 +01:00
|
|
|
app.Name = "tea"
|
2020-12-21 14:37:20 +01:00
|
|
|
app.Usage = "command line tool to interact with Gitea"
|
|
|
|
app.Description = appDescription
|
|
|
|
app.CustomAppHelpTemplate = helpTemplate
|
2018-09-03 08:43:00 +02:00
|
|
|
app.Version = Version + formatBuiltWith(Tags)
|
2020-01-04 18:44:25 +01:00
|
|
|
app.Commands = []*cli.Command{
|
|
|
|
&cmd.CmdLogin,
|
|
|
|
&cmd.CmdLogout,
|
2020-12-21 14:37:20 +01:00
|
|
|
&cmd.CmdAutocomplete,
|
|
|
|
|
2020-01-04 18:44:25 +01:00
|
|
|
&cmd.CmdIssues,
|
|
|
|
&cmd.CmdPulls,
|
|
|
|
&cmd.CmdLabels,
|
2020-12-21 14:37:20 +01:00
|
|
|
&cmd.CmdMilestones,
|
|
|
|
&cmd.CmdReleases,
|
2020-03-06 04:43:28 +01:00
|
|
|
&cmd.CmdTrackedTimes,
|
2020-12-21 14:37:20 +01:00
|
|
|
&cmd.CmdOrgs,
|
|
|
|
&cmd.CmdRepos,
|
|
|
|
|
2020-04-01 05:22:24 +02:00
|
|
|
&cmd.CmdOpen,
|
2020-07-17 17:30:02 +02:00
|
|
|
&cmd.CmdNotifications,
|
2018-09-03 08:43:00 +02:00
|
|
|
}
|
2019-08-13 12:59:13 +02:00
|
|
|
app.EnableBashCompletion = true
|
2018-09-03 08:43:00 +02:00
|
|
|
err := app.Run(os.Args)
|
|
|
|
if err != nil {
|
2020-12-16 17:18:10 +01:00
|
|
|
// app.Run already exits for errors implementing ErrorCoder,
|
|
|
|
// so we only handle generic errors with code 1 here.
|
|
|
|
fmt.Fprintf(app.ErrWriter, "Error: %v\n", err)
|
|
|
|
os.Exit(1)
|
2018-09-03 08:43:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatBuiltWith(Tags string) string {
|
|
|
|
if len(Tags) == 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return " built with: " + strings.Replace(Tags, " ", ", ", -1)
|
|
|
|
}
|
2020-12-21 14:37:20 +01:00
|
|
|
|
|
|
|
var appDescription = `tea is a productivity helper for Gitea. It can be used to manage most entities on one
|
|
|
|
or multiple Gitea instances and provides local helpers like 'tea pull checkout'.
|
|
|
|
tea makes use of context provided by the repository in $PWD if available, but is still
|
|
|
|
usable independently of $PWD. Configuration is persisted in $XDG_CONFIG_HOME/tea.
|
|
|
|
`
|
|
|
|
|
|
|
|
var helpTemplate = bold(`
|
|
|
|
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}`) + `
|
|
|
|
{{if .Version}}{{if not .HideVersion}}version {{.Version}}{{end}}{{end}}
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .Commands}} command [subcommand] [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
{{.Description | nindent 3 | trim}}{{end}}{{if .VisibleCommands}}
|
|
|
|
|
|
|
|
COMMANDS{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
{{.Name}}:{{range .VisibleCommands}}
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
{{range $index, $option := .VisibleFlags}}{{if $index}}
|
|
|
|
{{end}}{{$option}}{{end}}{{end}}
|
|
|
|
|
|
|
|
EXAMPLES
|
|
|
|
tea login add # add a login once to get started
|
|
|
|
|
|
|
|
tea pulls # list open pulls for the repo in $PWD
|
|
|
|
tea pulls --repo $HOME/foo # list open pulls for the repo in $HOME/foo
|
|
|
|
tea pulls --remote upstream # list open pulls for the repo pointed at by
|
|
|
|
# your local "upstream" git remote
|
|
|
|
# list open pulls for any gitea repo at the given login instance
|
|
|
|
tea pulls --repo gitea/tea --login gitea.com
|
|
|
|
|
|
|
|
tea milestone issues 0.7.0 # view open issues for milestone '0.7.0'
|
|
|
|
tea issue 189 # view contents of issue 189
|
|
|
|
tea open 189 # open web ui for issue 189
|
|
|
|
tea open milestones # open web ui for milestones
|
|
|
|
|
|
|
|
# send gitea desktop notifications every 5 minutes (bash + libnotify)
|
|
|
|
while :; do tea notifications --all -o simple | xargs -i notify-send {}; sleep 300; done
|
|
|
|
|
|
|
|
ABOUT
|
|
|
|
Written & maintained by The Gitea Authors.
|
|
|
|
If you find a bug or want to contribute, we'll welcome you at https://gitea.com/gitea/tea.
|
|
|
|
More info about Gitea itself on https://gitea.io.
|
|
|
|
`
|
|
|
|
|
|
|
|
func bold(t string) string {
|
|
|
|
return fmt.Sprintf("\033[1m%s\033[0m", t)
|
|
|
|
}
|