cmd

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2021 License: GPL-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "lh",
	Short: "lh provides CLI access to the Lighthouse API http://help.lighthouseapp.com/kb/api",
	Long: `lh provides CLI access to the Lighthouse API http://help.lighthouseapp.com/kb/api

Please specify your Lighthouse account name via -a, --account, the
LH_ACCOUNT environment variable or the config file.  If your
Lighthouse URL is 'https://your-account-name.lighthouseapp.com' then
your account name is 'your-account-name'.

Lighthouse requires a valid API token or email/password to
authenticate API requests.  Please specify a Lighthouse API token via
-t, --token, the LH_TOKEN environment variable or the config file.  If
you'd prefer to authenticate with an email/password, please specify it
via -e, --email, the LH_EMAIL environment variable, -p, --password,
the LH_PASSWORD environment variable or the config file.  If the
specified password has the form '@FILE', the password is instead read
from FILE.

Many subcommands work on resources that are Lighthouse
project-specific.  These commands require the project ID or name to be
specified via -p, --project, the LH_PROJECT environment variable or
the config file.

On Unix systems, the default config file is $HOME/.lh.yaml.  On
Windows systems, the default config file is
%HOMEDRIVE%\%HOMEPATH%\.lh.yaml, falling back to
%USERPROFILE%\.lh.yaml if necessary.  On all systems, the default can
be overridden with --config.

`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		account, token, email, password, interval, burstSize := viper.GetString("account"), viper.GetString("token"),
			viper.GetString("email"), viper.GetString("password"),
			viper.GetDuration("rate-limit-interval"), viper.GetInt("rate-limit-burst-size")
		if len(account) == 0 {
			FatalUsage(cmd, "Please specify Lighthouse account name via -a, --account, LH_ACCOUNT or config file")
		}
		lt := &lighthouse.Transport{
			TokenAsBasicAuth: true,
		}
		client := &http.Client{
			Transport: lt,
		}
		if len(token) > 0 {
			lt.Token = token
		} else if len(email) > 0 && len(password) > 0 {
			pw := password
			if strings.HasPrefix(password, "@") && len(password) > 1 {
				buf, err := ioutil.ReadFile(password[1:])
				if err != nil {
					FatalUsage(cmd, err)
				}
				pw = strings.TrimSpace(string(buf))
			}
			lt.Email = email
			lt.Password = pw
		} else {
			FatalUsage(cmd, "Please specify token or email & password")
		}
		if interval != time.Duration(0) {
			lt.RateLimitInterval = interval
			lt.RateLimitBurstSize = burstSize
		}
		service = lighthouse.NewService(account, client)
		service.RateLimitRetryRequests = true
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Account added in v0.4.1

func Account() string

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func FatalUsage added in v0.2.0

func FatalUsage(cmd *cobra.Command, v ...interface{})

func JSON

func JSON(v interface{})

func MilestoneID added in v0.2.0

func MilestoneID(milestoneStr string) (int, error)

func Project

func Project() int

func ProjectID added in v0.2.0

func ProjectID(projectStr string) (int, error)

func UserID added in v0.2.0

func UserID(userStr string) (int, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL