本文整理汇总了Golang中github.com/pgpst/pgpst/internal/github.com/pzduniak/cli.Context.GlobalBool方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GlobalBool方法的具体用法?Golang Context.GlobalBool怎么用?Golang Context.GlobalBool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pgpst/pgpst/internal/github.com/pzduniak/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalBool方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tokensAdd
//.........这里部分代码省略.........
writeError(c, err)
return 1
}
}
if input.Type == "auth" || input.Type == "code" {
fmt.Fprint(c.App.Writer, "Client ID: ")
input.ClientID, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.ClientID = strings.TrimSpace(input.ClientID)
fmt.Fprint(c.App.Writer, "Scope (seperated by commas): ")
scope, err := rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
scope = strings.TrimSpace(scope)
input.Scope = strings.Split(scope, ",")
}
}
// Validate the input
// Type has to be either auth or activate
if input.Type != "auth" && input.Type != "activate" && input.Type != "code" {
writeError(c, fmt.Errorf("Token type must be either auth or activate. Got %s.", input.Type))
return 1
}
// Scopes must exist
if input.Scope != nil && len(input.Scope) > 0 {
for _, scope := range input.Scope {
if _, ok := models.Scopes[scope]; !ok {
writeError(c, fmt.Errorf("Scope %s doesn't exist", scope))
return 1
}
}
}
// Owner must exist
cursor, err := r.Table("accounts").Get(input.Owner).Ne(nil).Run(session)
if err != nil {
writeError(c, err)
}
defer cursor.Close()
var exists bool
if err := cursor.One(&exists); err != nil {
writeError(c, err)
return 1
}
if !exists {
writeError(c, fmt.Errorf("Account %s doesn't exist", input.Owner))
return 1
}
// Application must exist
if input.ClientID != "" {
cursor, err = r.Table("applications").Get(input.ClientID).Ne(nil).Run(session)
if err != nil {
writeError(c, err)
}
defer cursor.Close()
var exists bool
if err := cursor.One(&exists); err != nil {
writeError(c, err)
return 1
}
if !exists {
writeError(c, fmt.Errorf("Application %s doesn't exist", input.ClientID))
return 1
}
}
// Insert into database
token := &models.Token{
ID: uniuri.NewLen(uniuri.UUIDLen),
DateCreated: time.Now(),
DateModified: time.Now(),
Owner: input.Owner,
ExpiryDate: input.ExpiryDate,
Type: input.Type,
Scope: input.Scope,
ClientID: input.ClientID,
}
if !c.GlobalBool("dry") {
if err := r.Table("tokens").Insert(token).Exec(session); err != nil {
writeError(c, err)
return 1
}
}
// Write a success message
fmt.Fprintf(c.App.Writer, "Created a new %s token with ID %s\n", token.Type, token.ID)
return 0
}
示例2: applicationsAdd
//.........这里部分代码省略.........
rd := bufio.NewReader(c.App.Env["reader"].(io.Reader))
var err error
// Acquire from interactive input
fmt.Fprint(c.App.Writer, "Owner's ID: ")
input.Owner, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Owner = strings.TrimSpace(input.Owner)
fmt.Fprint(c.App.Writer, "Application's name: ")
input.Name, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Name = strings.TrimSpace(input.Name)
fmt.Fprint(c.App.Writer, "Homepage URL: ")
input.Homepage, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Homepage = strings.TrimSpace(input.Homepage)
fmt.Fprint(c.App.Writer, "Description: ")
input.Description, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Description = strings.TrimSpace(input.Description)
fmt.Fprint(c.App.Writer, "Callback URL: ")
input.Callback, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Callback = strings.TrimSpace(input.Callback)
}
// Validate the input
// Check if account ID exists
cursor, err := r.Table("accounts").Get(input.Owner).Ne(nil).Run(session)
if err != nil {
writeError(c, err)
return 1
}
defer cursor.Close()
var exists bool
if err := cursor.One(&exists); err != nil {
writeError(c, err)
return 1
}
if !exists {
writeError(c, fmt.Errorf("Account %s doesn't exist", input.Owner))
return 1
}
// Homepage URL should be a URL
if !govalidator.IsURL(input.Homepage) {
writeError(c, fmt.Errorf("%s is not a URL", input.Homepage))
return 1
}
// Callback URL should be a URL
if !govalidator.IsURL(input.Callback) {
writeError(c, fmt.Errorf("%s is not a URL", input.Callback))
return 1
}
// Insert into database
application := &models.Application{
ID: uniuri.NewLen(uniuri.UUIDLen),
DateCreated: time.Now(),
DateModified: time.Now(),
Owner: input.Owner,
Secret: uniuri.NewLen(32),
Callback: input.Callback,
Homepage: input.Homepage,
Name: input.Name,
Description: input.Description,
}
if !c.GlobalBool("dry") {
if err := r.Table("applications").Insert(application).Exec(session); err != nil {
writeError(c, err)
return 1
}
}
// Write a success message
fmt.Fprintf(c.App.Writer, "Created a new application with ID %s\n", application.ID)
return 0
}
示例3: addressesAdd
func addressesAdd(c *cli.Context) int {
// Connect to RethinkDB
_, session, connected := connectToRethinkDB(c)
if !connected {
return 1
}
// Input struct
var input struct {
ID string `json:"id"`
Owner string `json:"owner"`
}
// Read JSON from stdin
if c.Bool("json") {
if err := json.NewDecoder(c.App.Env["reader"].(io.Reader)).Decode(&input); err != nil {
writeError(c, err)
return 1
}
} else {
// Buffer stdin
rd := bufio.NewReader(c.App.Env["reader"].(io.Reader))
var err error
// Acquire from interactive input
fmt.Fprintf(c.App.Writer, "Address: ")
input.ID, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.ID = strings.TrimSpace(input.ID)
fmt.Fprintf(c.App.Writer, "Owner ID: ")
input.Owner, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Owner = strings.TrimSpace(input.Owner)
}
// First of all, the address. Append domain if it has no such suffix.
if strings.Index(input.ID, "@") == -1 {
input.ID += "@" + c.GlobalString("default_domain")
}
// And format it
styledID := utils.NormalizeAddress(input.ID)
input.ID = utils.RemoveDots(styledID)
// Then check if it's taken.
cursor, err := r.Table("addresses").Get(input.ID).Ne(nil).Run(session)
if err != nil {
writeError(c, err)
return 1
}
defer cursor.Close()
var taken bool
if err := cursor.One(&taken); err != nil {
writeError(c, err)
return 1
}
if taken {
writeError(c, fmt.Errorf("Address %s is already taken", input.ID))
return 1
}
// Check if account ID exists
cursor, err = r.Table("accounts").Get(input.Owner).Ne(nil).Run(session)
if err != nil {
writeError(c, err)
}
defer cursor.Close()
var exists bool
if err := cursor.One(&exists); err != nil {
writeError(c, err)
return 1
}
if !exists {
writeError(c, fmt.Errorf("Account %s doesn't exist", input.ID))
return 1
}
// Insert the address into the database
address := &models.Address{
ID: input.ID,
StyledID: styledID,
DateCreated: time.Now(),
DateModified: time.Now(),
Owner: input.Owner,
}
if !c.GlobalBool("dry") {
if err := r.Table("addresses").Insert(address).Exec(session); err != nil {
writeError(c, err)
return 1
}
}
//.........这里部分代码省略.........