本文整理汇总了Golang中github.com/codegangsta/cli.Context.GlobalString方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GlobalString方法的具体用法?Golang Context.GlobalString怎么用?Golang Context.GlobalString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetChain
func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {
dataDir := ctx.GlobalString(DataDirFlag.Name)
blockDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "blockchain"))
if err != nil {
Fatalf("Could not open database: %v", err)
}
stateDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "state"))
if err != nil {
Fatalf("Could not open database: %v", err)
}
extraDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "extra"))
if err != nil {
Fatalf("Could not open database: %v", err)
}
eventMux := new(event.TypeMux)
chainManager := core.NewChainManager(blockDb, stateDb, eventMux)
pow := ethash.New()
txPool := core.NewTxPool(eventMux, chainManager.State, chainManager.GasLimit)
blockProcessor := core.NewBlockProcessor(stateDb, extraDb, pow, txPool, chainManager, eventMux)
chainManager.SetProcessor(blockProcessor)
return chainManager, blockDb, stateDb
}
示例2: cmdInit
func cmdInit(c *cli.Context) error {
username := c.Args().First()
if username == "" {
cli.ShowCommandHelp(c, "init")
return cli.NewExitError("", 0)
}
password := c.Args().Get(1)
if password == "" {
pwd, err := askPass()
if err != nil {
if err != gopass.ErrInterrupted {
return cli.NewExitError(err.Error(), 2)
}
return cli.NewExitError("", 2)
}
password = pwd
}
s, err := NewStore(c.GlobalString("store"), c.GlobalString("do-upgrades"),
c.GlobalString("policy-type"), c.GlobalString("policy-condition"), c.GlobalString("hooks-dir"))
if err != nil {
return cli.NewExitError(fmt.Sprintf("Error initializing whawty store: %s", err), 3)
}
if err := s.GetInterface().Init(username, password); err != nil {
return cli.NewExitError(fmt.Sprintf("Error initializing whawty store: %s", err), 3)
}
return cli.NewExitError(fmt.Sprintf("whawty store successfully initialized!"), 0)
}
示例3: MakeChain
// MakeChain creates a chain manager from set command line flags.
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb common.Database) {
datadir := ctx.GlobalString(DataDirFlag.Name)
cache := ctx.GlobalInt(CacheFlag.Name)
var err error
if chainDb, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "chaindata"), cache); err != nil {
Fatalf("Could not open database: %v", err)
}
if ctx.GlobalBool(OlympicFlag.Name) {
InitOlympic()
_, err := core.WriteTestNetGenesisBlock(chainDb, 42)
if err != nil {
glog.Fatalln(err)
}
}
eventMux := new(event.TypeMux)
pow := ethash.New()
//genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
chain, err = core.NewChainManager(chainDb, nil, pow, eventMux)
if err != nil {
Fatalf("Could not start chainmanager: %v", err)
}
proc := core.NewBlockProcessor(chainDb, pow, chain, eventMux)
chain.SetProcessor(proc)
return chain, chainDb
}
示例4: createImageCommandFunc
func createImageCommandFunc(c *cli.Context) {
var image string
if len(c.Args()) == 0 {
log.Fatal("You need to specify a image")
} else {
image = c.Args()[0]
}
clnt := client.New(c.GlobalString("server"))
if c.GlobalBool("debug") {
clnt.SetDebug()
}
s := client.Image{
Image: image,
Type: prompt.String("Type", prompt.Prompt{Default: "docker", FuncPtr: prompt.Enum, FuncInp: "file,docker"}),
BootTagID: *chooseTag(clnt, ""),
}
// Is this correct?
fmt.Println(string(s.JSON()))
if !prompt.Bool("Is this correct", true) {
os.Exit(1)
}
// Create image
clnt.Image.Create(&s)
}
示例5: makedag
func makedag(ctx *cli.Context) {
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
args := ctx.Args()
wrongArgs := func() {
utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
}
switch {
case len(args) == 2:
blockNum, err := strconv.ParseUint(args[0], 0, 64)
dir := args[1]
if err != nil {
wrongArgs()
} else {
dir = filepath.Clean(dir)
// seems to require a trailing slash
if !strings.HasSuffix(dir, "/") {
dir = dir + "/"
}
_, err = ioutil.ReadDir(dir)
if err != nil {
utils.Fatalf("Can't find dir")
}
fmt.Println("making DAG, this could take awhile...")
ethash.MakeDAG(blockNum, dir)
}
default:
wrongArgs()
}
}
示例6: blockRecovery
func blockRecovery(ctx *cli.Context) {
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
arg := ctx.Args().First()
if len(ctx.Args()) < 1 && len(arg) > 0 {
glog.Fatal("recover requires block number or hash")
}
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
utils.CheckLegalese(cfg.DataDir)
blockDb, err := ethdb.NewLDBDatabase(filepath.Join(cfg.DataDir, "blockchain"), cfg.DatabaseCache)
if err != nil {
glog.Fatalln("could not open db:", err)
}
var block *types.Block
if arg[0] == '#' {
block = core.GetBlockByNumber(blockDb, common.String2Big(arg[1:]).Uint64())
} else {
block = core.GetBlockByHash(blockDb, common.HexToHash(arg))
}
if block == nil {
glog.Fatalln("block not found. Recovery failed")
}
err = core.WriteHead(blockDb, block)
if err != nil {
glog.Fatalln("block write err", err)
}
glog.Infof("Recovery succesful. New HEAD %x\n", block.Hash())
}
示例7: attach
func attach(ctx *cli.Context) {
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
var client comms.EthereumClient
var err error
if ctx.Args().Present() {
client, err = comms.ClientFromEndpoint(ctx.Args().First(), codec.JSON)
} else {
cfg := comms.IpcConfig{
Endpoint: ctx.GlobalString(utils.IPCPathFlag.Name),
}
client, err = comms.NewIpcClient(cfg, codec.JSON)
}
if err != nil {
utils.Fatalf("Unable to attach to geth node - %v", err)
}
repl := newLightweightJSRE(
ctx.GlobalString(utils.JSpathFlag.Name),
client,
true,
)
if ctx.GlobalString(utils.ExecFlag.Name) != "" {
repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
} else {
repl.welcome()
repl.interactive()
}
}
示例8: push
func push(c *cli.Context) {
wd := ensureHome(c)
pkg := a1(c, "No package name given")
ver := a2(c, "Version is required")
h := NewClient(c.GlobalString("host"))
// Grab the latest version of the package from the server
p, err := h.Get(pkg)
if err != nil {
die(err)
}
// Build a release
r := &model.Release{
Version: ver,
Author: p.Author,
Date: time.Now(),
PackageId: p.ID,
Manifests: makeManifests(path.Join(wd, pkg)),
}
// Add it
p.Releases = append([]*model.Release{r}, p.Releases...)
info("Pushing %s %s to K8sPlace", pkg, ver)
//d, _ := json.Marshal(p)
//fmt.Println(string(d))
if err := h.Update(p); err != nil {
die(err)
}
ftw("Updated %s", p.Name)
}
示例9: RecordGenerator
// RecordGenerator abstracts from the way the strings are specified, e.g. via
// stdin a file or directly on the command line
func RecordGenerator(c *cli.Context) chan *Record {
columnSpec, err := ParseColumnSpec(c.GlobalString("f"))
if err != nil {
log.Fatal(err)
}
// stdin
if len(c.Args()) == 0 || (len(c.Args()) == 1 && c.Args()[0] == "-") {
return RecordGeneratorFileDelimiter(os.Stdin, columnSpec, c.GlobalString("delimiter"))
}
// from filename
if len(c.Args()) == 1 {
filename := c.Args()[0]
if _, err := os.Stat(filename); err == nil {
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
return RecordGeneratorFile(file, columnSpec)
}
log.Fatalf("no such file: %s\n", filename)
}
// direct
if len(c.Args()) == 2 {
records := make(chan *Record)
go func() {
records <- &Record{Fields: c.Args(), left: 0, right: 1}
close(records)
}()
return records
}
return nil
}
示例10: setup
func (this *App) setup(c *cli.Context) error {
if this.client == nil {
this.client = api.NewClient(c.GlobalString("server"))
}
if this.user == nil {
// try load user from config
if this.config != nil && this.config.CurrentUser != "" {
this.user, _ = this.store.FindUserByKey(this.config.CurrentUser)
}
// still not found
if this.user == nil {
this.user = this.selectCurrentUser()
}
}
if this.user == nil {
return ErrNoUser
}
if err := this.client.Register(this.user); err != nil {
return err
}
// save config
if this.config == nil {
this.config = &AppConfig{
CurrentUser: this.user.Key,
}
this.saveConfig(this.config)
}
return nil
}
示例11: getConfigFilename
// getConfigFilename gets the absolute filename of the config file specified by
// the ConfigFilename flag, and whether it exists.
//
// If the ConfigFilename exists, then it is returned as an absolute path.
// If neither of those exist, the absolute ConfigFilename is returned.
func getConfigFilename(context *cli.Context) (string, bool) {
cf := context.GlobalString("config-filename")
if filepath.IsAbs(cf) {
// Absolute path specified; user knows what they want.
_, err := os.Stat(cf)
return cf, err == nil
}
absCF, err := filepath.Abs(cf)
if err != nil {
// syscall failure; treat as if file doesn't exist.
return cf, false
}
if _, err := os.Stat(absCF); err == nil {
// File exists on relative path.
return absCF, true
}
// Check for config file on path relative to executable.
exeFile := os.Args[0]
exeDir := filepath.Dir(exeFile)
absCF = filepath.Join(exeDir, cf)
if _, err := os.Stat(absCF); err == nil {
return absCF, true
}
// This is probably what the user expects if it wasn't found anywhere else.
return absCF, false
}
示例12: getConfigFilename
// getConfigFilename gets the absolute filename of the config file specified by
// the ConfigFilename flag, and whether it exists.
//
// If the (relative or absolute) ConfigFilename exists, then it is returned.
// If the ConfigFilename exists in a valid XDG path, then it is returned.
// If neither of those exist, the (relative or absolute) ConfigFilename is returned.
func getConfigFilename(context *cli.Context) (string, bool) {
cf := context.GlobalString("config-filename")
if filepath.IsAbs(cf) {
// Absolute path specified; user knows what they want.
_, err := os.Stat(cf)
return cf, err == nil
}
absCF, err := filepath.Abs(cf)
if err != nil {
// syscall failure; treat as if file doesn't exist.
return cf, false
}
if _, err := os.Stat(absCF); err == nil {
// File exists on relative path.
return absCF, true
}
if xdgCF, err := xdg.Config.Find(cf); err == nil {
// File exists in an XDG directory.
return xdgCF, true
}
// Default to relative path. This is probably what the user expects if
// it wasn't found anywhere else.
return absCF, false
}
示例13: installAction
func installAction(ctx *cli.Context) {
server := ctx.GlobalString("server")
ref := ctx.String("ref")
if len(ctx.Args()) == 0 {
log.Fatal("Need args")
}
repo := ctx.Args().Get(0)
log.Println(repo)
u := url.URL{
Scheme: "http",
Host: server,
}
// guess repo
if !strings.Contains(repo, "/") {
luckyURL := u
luckyURL.Path = "/lucky/" + repo
var err error
repo, err = httpGetString(luckyURL.String())
if err != nil {
log.Fatal(err)
}
if repo == "" {
log.Fatal("Guess repo failed, require fullname <owner/reponame>")
}
}
log.Println("use repo:", repo)
binURL := u
binURL.Path = fmt.Sprintf("%s/%s/%s/%s", repo, ref, runtime.GOOS, runtime.GOARCH)
getBinary(binURL, figureBinName(repo))
}
示例14: Fetch
// Fetch returns exercism problems.
func Fetch(ctx *cli.Context) {
c, err := config.New(ctx.GlobalString("config"))
if err != nil {
log.Fatal(err)
}
client := api.NewClient(c)
problems, err := client.Fetch(ctx.Args())
if err != nil {
log.Fatal(err)
}
submissionInfo, err := client.Submissions()
if err != nil {
log.Fatal(err)
}
if err := setSubmissionState(problems, submissionInfo); err != nil {
log.Fatal(err)
}
hw := user.NewHomework(problems, c)
if err := hw.Save(); err != nil {
log.Fatal(err)
}
hw.Summarize(user.HWAll)
}
示例15: statusCmd
func statusCmd(c *cli.Context) {
migrationsPath := c.GlobalString("migrations")
targetPath := c.GlobalString("target")
migrationsPath, err := migrations.AbsMigrationsPath(migrationsPath)
if err != nil {
fmt.Printf("Error determining the migrations path: %s\n", err.Error())
os.Exit(1)
}
list, err := migrations.List(migrationsPath)
if err != nil {
fmt.Printf("Error listing the available migrations: %s\n", err.Error())
os.Exit(1)
}
timestamp, err := migrations.CurrentTimestamp(targetPath)
if err != nil {
fmt.Printf("Error reading the current timestamp: %s\n", err.Error())
os.Exit(1)
}
if last := migrations.Last(list, timestamp); last != nil {
fmt.Printf("Last migration executed: %s\n", last.Name)
} else {
fmt.Printf("No migration executed yet!\n")
}
fmt.Printf("Pending migrations: %d\n", len(migrations.Pending(list, timestamp)))
}