parsecli

package
v0.0.0-...-eec3be4 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: BSD-3-Clause Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LegacyParseFormat = iota
	ParseFormat
	HerokuFormat

	ParseLocal   = ".parse.local"
	ParseProject = ".parse.project"
	DefaultKey   = "_default"
)
View Source
const (
	Version        = "3.0.5"
	CloudDir       = "cloud"
	HostingDir     = "public"
	DefaultBaseURL = "https://api.parse.com/1/"
)
View Source
const (
	SampleSource = `` /* 188-byte string literal not displayed */

	SampleHTML = `` /* 779-byte string literal not displayed */

)
View Source
const ConfigDir = "config"

Variables

View Source
var LegacyConfigFile = filepath.Join(ConfigDir, "global.json")
View Source
var NewProjectFiles = []struct {
	Dirname, Filename, Content string
}{
	{"cloud", "main.js", SampleSource},
	{"public", "index.html", SampleHTML},
}
View Source
var UserAgent = fmt.Sprintf("parse-cli-%s-%s", runtime.GOOS, Version)

Functions

func CloneSampleCloudCode

func CloneSampleCloudCode(e *Env, dumpTemplate bool) error

func CreateConfigWithContent

func CreateConfigWithContent(path, content string) error

func ErrorString

func ErrorString(e *Env, err error) string

errorString returns the error string with our without the stack trace depending on the Environment variable. this exists because we want plain messages for end users, but when we're working on the CLI we want the stack trace for debugging.

func FetchHerokuAppName

func FetchHerokuAppName(id string, e *Env) (string, error)

func GetConfigFile

func GetConfigFile(e *Env) string

func GetLegacyProjectRoot

func GetLegacyProjectRoot(e *Env, cur string) string

func GetProjectRoot

func GetProjectRoot(e *Env, cur string) string

func HerokuAppNotFound

func HerokuAppNotFound(err error) bool

func IsProjectDir

func IsProjectDir(cur string) bool

func Last4

func Last4(str string) string

func MakeCorrections

func MakeCorrections(commands []string, args []string) string

MakeCorrections can be used to automatically correct the incorrect command in input args and return either an action that was taken or a suggestions message. One can also provide a map of aliases and related conversions

func NewAppHarness

func NewAppHarness(t testing.TB) (*Harness, []*App)

func NewHerokuAPIClient

func NewHerokuAPIClient(e *Env) (*heroku.Client, error)

func PrintDefault

func PrintDefault(e *Env, defaultApp string) error

func RunNoArgs

func RunNoArgs(e *Env, f func(*Env) error) cobraRun

RunNoArgs wraps a run function that shouldn't get any arguments.

func RunWithArgs

func RunWithArgs(e *Env, f func(*Env, []string) error) cobraRun

RunWithArgs wraps a run function that can access arguments to cobraCmd

func RunWithArgsClient

func RunWithArgsClient(e *Env, f func(*Env, *Context, []string) error) cobraRun

RunWithArgsClient wraps a run function that should get an app, whee the default is picked from the config in the current working directory. It also passes args to the runner function

func RunWithClient

func RunWithClient(e *Env, f func(*Env, *Context) error) cobraRun

RunWithClient wraps a run function that should get an app, when the default is picked from the config in the current working directory.

func RunWithClientConfirm

func RunWithClientConfirm(e *Env, f func(*Env, *Context) error) cobraRun

RunWithClientConfirm wraps a run function that takes an app name or asks for confirmation to use the default app name instead

func SetDefault

func SetDefault(e *Env, newDefault, defaultApp string, c Config) error

func SetHerokuDefault

func SetHerokuDefault(e *Env, newDefault, defaultApp string, herokuConfig *HerokuConfig) error

func SetParserEmail

func SetParserEmail(e *Env, email string) error

func StoreConfig

func StoreConfig(e *Env, c Config) error

func StoreProjectConfig

func StoreProjectConfig(e *Env, c Config) error

func SuggestCommands

func SuggestCommands(given string, available []string) []string

SuggestCommands can be used to match a given word which is very similar to one among the list of available commands.

Types

type App

type App struct {
	Name                          string `json:"appName"`
	DashboardURL                  string `json:"dashboardURL"`
	ApplicationID                 string `json:"applicationId"`
	ClientKey                     string `json:"clientKey"`
	JavaScriptKey                 string `json:"javascriptKey"`
	WindowsKey                    string `json:"windowsKey"`
	WebhookKey                    string `json:"webhookKey"`
	RestKey                       string `json:"restKey"`
	MasterKey                     string `json:"masterKey"`
	ClientPushEnabled             bool   `json:"clientPushEnabled"`
	ClientClassCreationEnabled    bool   `json:"clientClassCreationEnabled"`
	RequireRevocableSessions      bool   `json:"requireRevocableSessions"`
	RevokeSessionOnPasswordChange bool   `json:"revokeSessionOnPasswordChange"`
}

func FetchAppKeys

func FetchAppKeys(e *Env, appID string) (*App, error)

type AppConfig

type AppConfig interface {
	GetApplicationID() string
	GetMasterKey(e *Env) (string, error)
	GetApplicationAuth(e *Env) (string, error)
	GetLink() string
}

type Apps

type Apps struct {
	Login Login
}

func (*Apps) CreateApp

func (a *Apps) CreateApp(e *Env, givenName string, retries int) (*App, error)

func (*Apps) PrintApp

func (a *Apps) PrintApp(e *Env, params *App) error

func (*Apps) RestFetchApps

func (a *Apps) RestFetchApps(e *Env) ([]*App, error)

func (*Apps) SelectApp

func (a *Apps) SelectApp(apps []*App, msg string, e *Env) (*App, error)

func (*Apps) ShowApps

func (a *Apps) ShowApps(e *Env, appName string) error

type Config

type Config interface {
	App(string) (AppConfig, error)
	AddAlias(string, string) error
	SetDefaultApp(string) error

	GetProjectConfig() *ProjectConfig
	GetDefaultApp() string
	GetNumApps() int
	PrettyPrintApps(*Env)
}

func ConfigFromDir

func ConfigFromDir(dir string) (Config, error)

type Context

type Context struct {
	Config    Config
	AppName   string
	AppConfig AppConfig
}

type Credentials

type Credentials struct {
	Email    string
	Password string
	Token    string
}

type Env

type Env struct {
	Root            string // project root
	Server          string // parse api server
	Type            int    // project type
	ParserEmail     string // email associated with developer parse account
	ErrorStack      bool
	Out             io.Writer
	Err             io.Writer
	In              io.Reader
	Exit            func(int)
	Clock           clock.Clock
	ParseAPIClient  *ParseAPIClient
	HerokuAPIClient *heroku.Client
}

type Harness

type Harness struct {
	T     testing.TB
	Out   bytes.Buffer
	Err   bytes.Buffer
	Clock *clock.Mock
	Env   *Env
	// contains filtered or unexported fields
}

func NewHarness

func NewHarness(t testing.TB) *Harness

func NewTokenHarness

func NewTokenHarness(t testing.TB) *Harness

func (*Harness) MakeEmptyRoot

func (h *Harness) MakeEmptyRoot()

func (*Harness) MakeWithConfig

func (h *Harness) MakeWithConfig(global string)

func (*Harness) Stop

func (h *Harness) Stop()

type HerokuAppConfig

type HerokuAppConfig struct {
	ParseAppID        string `json:"parseAppId,omitempty"`
	MasterKey         string `json:"masterKey,omitempty"`
	HerokuAppID       string `json:"herokuAppId,omitempty"`
	HerokuAccessToken string `json:"herokuAccessToken,omitempty"`
	Link              string `json:"link,omitempty"`
	// contains filtered or unexported fields
}

func (*HerokuAppConfig) GetApplicationAuth

func (c *HerokuAppConfig) GetApplicationAuth(e *Env) (string, error)

func (*HerokuAppConfig) GetApplicationID

func (c *HerokuAppConfig) GetApplicationID() string
func (c *HerokuAppConfig) GetLink() string

func (*HerokuAppConfig) GetMasterKey

func (c *HerokuAppConfig) GetMasterKey(e *Env) (string, error)

func (*HerokuAppConfig) WithHiddenAccessToken

func (c *HerokuAppConfig) WithHiddenAccessToken(accessToken string) *HerokuAppConfig

func (*HerokuAppConfig) WithHiddenMasterKey

func (c *HerokuAppConfig) WithHiddenMasterKey(masterKey string) *HerokuAppConfig

type HerokuConfig

type HerokuConfig struct {
	Applications  map[string]*HerokuAppConfig `json:"applications,omityempty"`
	ProjectConfig *ProjectConfig              `json:"-"`
}

func (*HerokuConfig) AddAlias

func (c *HerokuConfig) AddAlias(name, link string) error

func (*HerokuConfig) App

func (c *HerokuConfig) App(name string) (AppConfig, error)

func (*HerokuConfig) GetDefaultApp

func (c *HerokuConfig) GetDefaultApp() string

func (*HerokuConfig) GetNumApps

func (c *HerokuConfig) GetNumApps() int

func (*HerokuConfig) GetProjectConfig

func (c *HerokuConfig) GetProjectConfig() *ProjectConfig

func (*HerokuConfig) PrettyPrintApps

func (c *HerokuConfig) PrettyPrintApps(e *Env)

func (*HerokuConfig) SetDefaultApp

func (c *HerokuConfig) SetDefaultApp(name string) error

type Login

type Login struct {
	Credentials Credentials
	TokenReader io.Reader
}

func (*Login) AuthToken

func (l *Login) AuthToken(e *Env, token string) (string, error)

func (*Login) AuthUser

func (l *Login) AuthUser(e *Env, strict bool) error

func (*Login) AuthUserWithToken

func (l *Login) AuthUserWithToken(e *Env, strict bool) (string, error)

func (*Login) GetTokenCredentials

func (l *Login) GetTokenCredentials(e *Env, email string) (bool, *Credentials, error)

func (*Login) HelpCreateToken

func (l *Login) HelpCreateToken(e *Env) (string, error)

func (*Login) StoreCredentials

func (l *Login) StoreCredentials(e *Env, email string, credentials *Credentials) error

type ParseAPIClient

type ParseAPIClient struct {
	APIClient *parse.Client
}

ParseAPIClient is the http client used by parse-cli

func NewParseAPIClient

func NewParseAPIClient(e *Env) (*ParseAPIClient, error)

func (*ParseAPIClient) Delete

func (c *ParseAPIClient) Delete(u *url.URL, result interface{}) (*http.Response, error)

Delete performs a DELETE method call on the given url and unmarshal response into result.

func (*ParseAPIClient) Do

func (c *ParseAPIClient) Do(req *http.Request, body, result interface{}) (*http.Response, error)

Do is a wrapper for parse.Client.Do

func (*ParseAPIClient) Get

func (c *ParseAPIClient) Get(u *url.URL, result interface{}) (*http.Response, error)

Get performs a GET method call on the given url and unmarshal response into result.

func (*ParseAPIClient) Post

func (c *ParseAPIClient) Post(u *url.URL, body, result interface{}) (*http.Response, error)

Post performs a POST method call on the given url with the given body and unmarshal response into result.

func (*ParseAPIClient) Put

func (c *ParseAPIClient) Put(u *url.URL, body, result interface{}) (*http.Response, error)

Put performs a PUT method call on the given url with the given body and unmarshal response into result.

func (*ParseAPIClient) RoundTrip

func (c *ParseAPIClient) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip is a wrapper for parse.Client.RoundTrip

func (*ParseAPIClient) WithCredentials

func (c *ParseAPIClient) WithCredentials(cr parse.Credentials) *ParseAPIClient

WithCredentials is a wrapper for parse.Client.WithCredentials

type ParseAppConfig

type ParseAppConfig struct {
	ApplicationID string `json:"applicationId,omitempty"`
	MasterKey     string `json:"masterKey,omitempty"`
	Link          string `json:"link,omitempty"`
	// contains filtered or unexported fields
}

func (*ParseAppConfig) GetApplicationAuth

func (c *ParseAppConfig) GetApplicationAuth(e *Env) (string, error)

func (*ParseAppConfig) GetApplicationID

func (c *ParseAppConfig) GetApplicationID() string
func (c *ParseAppConfig) GetLink() string

func (*ParseAppConfig) GetMasterKey

func (c *ParseAppConfig) GetMasterKey(e *Env) (string, error)

func (*ParseAppConfig) WithInternalMasterKey

func (c *ParseAppConfig) WithInternalMasterKey(masterKey string) *ParseAppConfig

type ParseConfig

type ParseConfig struct {
	Applications  map[string]*ParseAppConfig `json:"applications,omitempty"`
	ProjectConfig *ProjectConfig             `json:"-"`
}

func (*ParseConfig) AddAlias

func (c *ParseConfig) AddAlias(name, link string) error

func (*ParseConfig) App

func (c *ParseConfig) App(name string) (AppConfig, error)

func (*ParseConfig) GetDefaultApp

func (c *ParseConfig) GetDefaultApp() string

func (*ParseConfig) GetNumApps

func (c *ParseConfig) GetNumApps() int

func (*ParseConfig) GetProjectConfig

func (c *ParseConfig) GetProjectConfig() *ProjectConfig

func (*ParseConfig) PrettyPrintApps

func (c *ParseConfig) PrettyPrintApps(e *Env)

func (*ParseConfig) SetDefaultApp

func (c *ParseConfig) SetDefaultApp(name string) error

type ParseProjectConfig

type ParseProjectConfig struct {
	JSSDK string `json:"jssdk,omitempty"`
}

type ProjectConfig

type ProjectConfig struct {
	// Type indicates the type of config.
	// Some examples are legacy, parse, etc.
	Type int `json:"project_type,omitempty"`
	// Parse stores the project config for Parse type.
	// Currently jssdk version is the only
	// project level config for Parse type.
	Parse *ParseProjectConfig `json:"parse,omitempty"`
	// ParserEmail is an email id of the Parse developer.
	// It is associated with this project.
	// It is used to fetch appropriate credentials from netrc.
	ParserEmail string `json:"email,omitempty"`
}

type TransportFunc

type TransportFunc func(r *http.Request) (*http.Response, error)

func (TransportFunc) RoundTrip

func (t TransportFunc) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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