本文整理汇总了Golang中github.com/pgpst/pgpst/internal/github.com/pzduniak/cli.Context.GlobalString方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GlobalString方法的具体用法?Golang Context.GlobalString怎么用?Golang Context.GlobalString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pgpst/pgpst/internal/github.com/pzduniak/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: connectToRethinkDB
func connectToRethinkDB(c *cli.Context) (*r.ConnectOpts, *r.Session, bool) {
opts, err := utils.ParseRethinkDBString(c.GlobalString("rethinkdb"))
if err != nil {
writeError(c, err)
return nil, nil, false
}
session, err := r.Connect(opts)
if err != nil {
writeError(c, err)
return nil, nil, false
}
return &opts, session, true
}
示例2: 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
}
}
//.........这里部分代码省略.........
示例3: accountsAdd
func accountsAdd(c *cli.Context) int {
// Connect to RethinkDB
_, session, connected := connectToRethinkDB(c)
if !connected {
return 1
}
// Input struct
var input struct {
MainAddress string `json:"main_address"`
Password string `json:"password"`
Subscription string `json:"subscription"`
AltEmail string `json:"alt_email"`
Status string `json:"status"`
}
// 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.Fprint(c.App.Writer, "Main address: ")
input.MainAddress, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.MainAddress = strings.TrimSpace(input.MainAddress)
fmt.Fprint(c.App.Writer, "Password: ")
input.Password, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Password = strings.TrimSpace(input.Password)
/*password, err := speakeasy.FAsk(rd, "Password: ")
if err != nil {
writeError(c, err)
return 1
}
input.Password = password*/
fmt.Fprint(c.App.Writer, "Subscription [beta/admin]: ")
input.Subscription, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Subscription = strings.TrimSpace(input.Subscription)
fmt.Fprint(c.App.Writer, "Alternative address: ")
input.AltEmail, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.AltEmail = strings.TrimSpace(input.AltEmail)
fmt.Fprint(c.App.Writer, "Status [inactive/active/suspended]: ")
input.Status, err = rd.ReadString('\n')
if err != nil {
writeError(c, err)
return 1
}
input.Status = strings.TrimSpace(input.Status)
}
// Analyze the input
// First of all, the address. Append domain if it has no such suffix.
if strings.Index(input.MainAddress, "@") == -1 {
input.MainAddress += "@" + c.GlobalString("default_domain")
}
// And format it
styledID := utils.NormalizeAddress(input.MainAddress)
input.MainAddress = utils.RemoveDots(styledID)
// Then check if it's taken.
cursor, err := r.Table("addresses").Get(input.MainAddress).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 {
//.........这里部分代码省略.........