本文整理汇总了Golang中github.com/codegangsta/cli.Context.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.String方法的具体用法?Golang Context.String怎么用?Golang Context.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startDirectory
func startDirectory(c *cli.Context) {
fmt.Println("Starting full-blown service-directory")
// var apiReg = svcreg.NewGenericAPIVersionRegistry()
// var svcReg = svcreg.NewGenericServiceRegistry()
// var hostReg = svcreg.NewGenericHostRegistry(svcReg)
//
// var outboundEvents = make(chan evntsrc.Event)
// var handler = evntsrc.NewEventHandler()
// var dirSvc = svcreg.NewServiceRegistryWebService(outboundEvents, apiReg, svcReg, hostReg)
// var nsqSink, err = utils.NewNsqSink()
// if err != nil {
// fmt.Println("Failed to initialize the NSQ communications")
// return
// }
// handler.Use("ADD_ServiceDefinition", nsqSink.Publish)
// var nsqCancelChan = keepProcessing(outboundEvents, handler.Handle)
//
// var m = martini.Classic()
// m.Use(render.Renderer())
// m.Action(dirSvc.Route().Handle)
// http.HandleFunc("/service-directory/", func(w http.ResponseWriter, r *http.Request) {
// r.URL, _ = url.Parse(strings.TrimPrefix(r.URL.String(), "/service-directory"))
// m.ServeHTTP(w, r)
// })
// TODO (enzian) gracefully stop the service.
log.Fatal(http.ListenAndServe(c.String("u"), nil))
// nsqCancelChan <- true
}
示例2: runWeb
func runWeb(ctx *cli.Context) {
if ctx.IsSet("config") {
setting.CustomConf = ctx.String("config")
}
routers.GlobalInit()
checkVersion()
}
示例3: Run
func (cmd RepoPlugins) Run(c *cli.Context) {
var repos []models.PluginRepo
repoName := c.String("r")
repos = cmd.config.PluginRepos()
if repoName == "" {
cmd.ui.Say(T("Getting plugins from all repositories ... "))
} else {
index := cmd.findRepoIndex(repoName)
if index != -1 {
cmd.ui.Say(T("Getting plugins from repository '") + repoName + "' ...")
repos = []models.PluginRepo{repos[index]}
} else {
cmd.ui.Failed(repoName + T(" does not exist as an available plugin repo."+"\nTip: use `add-plugin-repo` command to add repos."))
}
}
cmd.ui.Say("")
repoPlugins, repoError := cmd.pluginRepo.GetPlugins(repos)
cmd.printTable(repoPlugins)
cmd.printErrors(repoError)
}
示例4: getPassword
func getPassword(context *cli.Context) (password string, err error) {
password = context.String("password")
if len(password) > 0 {
return password, nil
}
return gopass.GetPass("Plex password: ")
}
示例5: doObjectStoreAddImage
func doObjectStoreAddImage(c *cli.Context) error {
var err error
v := url.Values{}
objectstoreUUID, err := getUUID(c, KEY_OBJECTSTORE, true, err)
imageUUID, err := getUUID(c, KEY_IMAGE, false, err)
imageName, err := getName(c, "image-name", false, err)
if err != nil {
return err
}
imageFile := c.String("image-file")
if imageFile == "" {
return genRequiredMissingError("image-file")
}
imageConfig := api.ObjectStoreImageConfig{
ImageFile: imageFile,
}
if imageUUID != "" {
v.Set(KEY_IMAGE, imageUUID)
}
if imageName != "" {
v.Set("image-name", imageName)
}
request := "/objectstores/" + objectstoreUUID + "/images/add?" + v.Encode()
return sendRequestAndPrint("POST", request, imageConfig)
}
示例6: setOrganization
func (cmd Login) setOrganization(c *cli.Context) (isOrgSet bool) {
orgName := c.String("o")
if orgName == "" {
availableOrgs := []models.Organization{}
apiErr := cmd.orgRepo.ListOrgs(func(o models.Organization) bool {
availableOrgs = append(availableOrgs, o)
return len(availableOrgs) < maxChoices
})
if apiErr != nil {
cmd.ui.Failed("Error finding avilable orgs\n%s", apiErr.Error())
}
if len(availableOrgs) == 1 {
cmd.targetOrganization(availableOrgs[0])
return true
}
orgName = cmd.promptForOrgName(availableOrgs)
if orgName == "" {
cmd.ui.Say("")
return false
}
}
org, err := cmd.orgRepo.FindByName(orgName)
if err != nil {
cmd.ui.Failed("Error finding org %s\n%s", terminal.EntityNameColor(orgName), err.Error())
}
cmd.targetOrganization(org)
return true
}
示例7: Run
func (cmd CreateOrg) Run(c *cli.Context) {
name := c.Args()[0]
cmd.ui.Say(T("Creating org {{.OrgName}} as {{.Username}}...",
map[string]interface{}{
"OrgName": terminal.EntityNameColor(name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
org := models.Organization{OrganizationFields: models.OrganizationFields{Name: name}}
quotaName := c.String("q")
if quotaName != "" {
quota, err := cmd.quotaRepo.FindByName(quotaName)
if err != nil {
cmd.ui.Failed(err.Error())
}
org.QuotaDefinition.Guid = quota.Guid
}
err := cmd.orgRepo.Create(org)
if err != nil {
if apiErr, ok := err.(errors.HttpError); ok && apiErr.ErrorCode() == errors.ORG_EXISTS {
cmd.ui.Ok()
cmd.ui.Warn(T("Org {{.OrgName}} already exists",
map[string]interface{}{"OrgName": name}))
return
} else {
cmd.ui.Failed(err.Error())
}
}
cmd.ui.Ok()
cmd.ui.Say(T("\nTIP: Use '{{.Command}}' to target new org",
map[string]interface{}{"Command": terminal.CommandColor(cf.Name() + " target -o " + name)}))
}
示例8: restoreContainer
func restoreContainer(context *cli.Context, spec *specs.Spec, config *configs.Config, imagePath string) (code int, err error) {
var (
rootuid = 0
rootgid = 0
id = context.Args().First()
)
factory, err := loadFactory(context)
if err != nil {
return -1, err
}
container, err := factory.Load(id)
if err != nil {
container, err = factory.Create(id, config)
if err != nil {
return -1, err
}
}
options := criuOptions(context)
status, err := container.Status()
if err != nil {
logrus.Error(err)
}
if status == libcontainer.Running {
fatalf("Container with id %s already running", id)
}
setManageCgroupsMode(context, options)
// ensure that the container is always removed if we were the process
// that created it.
detach := context.Bool("detach")
if !detach {
defer destroy(container)
}
process := &libcontainer.Process{}
tty, err := setupIO(process, rootuid, rootgid, "", false, detach)
if err != nil {
return -1, err
}
defer tty.Close()
handler := newSignalHandler(tty, !context.Bool("no-subreaper"))
if err := container.Restore(process, options); err != nil {
return -1, err
}
if err := tty.ClosePostStart(); err != nil {
return -1, err
}
if pidFile := context.String("pid-file"); pidFile != "" {
if err := createPidFile(pidFile, process); err != nil {
process.Signal(syscall.SIGKILL)
process.Wait()
return -1, err
}
}
if detach {
return 0, nil
}
return handler.forward(process)
}
示例9: NewDriver
// NewDriver creates a new MACVLAN Driver
func NewDriver(version string, ctx *cli.Context) (*Driver, error) {
docker, err := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
if err != nil {
return nil, fmt.Errorf("could not connect to docker: %s", err)
}
// lower bound of v4 MTU is 68-bytes per rfc791
if ctx.Int("mtu") <= 0 {
cliMTU = defaultMTU
} else if ctx.Int("mtu") >= minMTU {
cliMTU = ctx.Int("mtu")
} else {
log.Fatalf("The MTU value passed [ %d ] must be greater than [ %d ] bytes per rfc791", ctx.Int("mtu"), minMTU)
}
// Set the default mode to bridge
if ctx.String("mode") == "" {
macvlanMode = bridgeMode
}
switch ctx.String("mode") {
case bridgeMode:
macvlanMode = bridgeMode
// todo: in other modes if relevant
}
d := &Driver{
networks: networkTable{},
dockerer: dockerer{
client: docker,
},
}
return d, nil
}
示例10: before
func before(c *cli.Context) error {
initLogFormatter()
initHelpAndVersionFlags()
initAppHelpTemplate()
// Log level
if logLevel, err := log.ParseLevel(c.String(LogLevelKey)); err != nil {
log.Fatal("[BITRISE_CLI] - Failed to parse log level:", err)
} else {
log.SetLevel(logLevel)
}
// Befor parsing cli, and running command
// we need to decide wich path will be used by envman
envman.CurrentEnvStoreFilePath = c.String(PathKey)
if envman.CurrentEnvStoreFilePath == "" {
if path, err := envStorePathInCurrentDir(); err != nil {
log.Fatal("[ENVMAN] - Failed to set envman work path in current dir:", err)
} else {
envman.CurrentEnvStoreFilePath = path
}
}
envman.ToolMode = c.Bool(ToolKey)
if envman.ToolMode {
log.Info("[ENVMAN] - Tool mode on")
}
if _, err := envman.GetConfigs(); err != nil {
log.Fatal("[ENVMAN] - Failed to init configs:", err)
}
return nil
}
示例11: create
func create(c *cli.Context) {
f := c.String("config")
if len(f) == 0 {
f = "dashing.json"
}
conf := Dashing{
Name: "Dashing",
Package: "dashing",
Index: "index.html",
Selectors: map[string]interface{}{
"title": "Package",
"dt a": "Command",
},
Ignore: []string{"ABOUT"},
}
j, err := json.MarshalIndent(conf, "", " ")
if err != nil {
panic("The programmer did something dumb.")
}
err = ioutil.WriteFile(f, j, 0755)
if err != nil {
fmt.Errorf("Could not initialize JSON file: %s", err)
os.Exit(1)
}
fmt.Printf("You may now edit %s", f)
}
示例12: getFlavorTasks
// Retrieves tasks from specified flavor
func getFlavorTasks(c *cli.Context, w io.Writer) error {
err := checkArgNum(c.Args(), 1, "flavor tasks <id> [<options>]")
if err != nil {
return err
}
id := c.Args().First()
state := c.String("state")
options := &photon.TaskGetOptions{
State: state,
}
client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
if err != nil {
return err
}
taskList, err := client.Esxclient.Flavors.GetTasks(id, options)
if err != nil {
return err
}
err = printTaskList(taskList.Items, c)
if err != nil {
return err
}
return nil
}
示例13: newDB
func newDB(c *cli.Context) *sqlx.DB {
db := sqlx.MustConnect("postgres", c.String("db"))
if err := conveyor.MigrateUp(db); err != nil {
panic(err)
}
return db
}
示例14: runImport
func runImport(c *cli.Context) {
var input io.ReadCloser
var err error
input = os.Stdin
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
inputFile := c.String("input")
if inputFile != "" {
input, err = os.Open(inputFile)
if err != nil {
log.Fatal(err)
}
defer input.Close()
}
bytes, err := ioutil.ReadAll(input)
if err != nil {
log.Fatal(err)
}
cfg, err = cfg.Import(bytes)
if err != nil {
log.Fatal(err)
}
if err := cfg.Save(); err != nil {
log.Fatal(err)
}
}
示例15: doBuild
func doBuild(c *cli.Context) {
home := os.Getenv("HOME")
outputDir := os.ExpandEnv(c.String("dir"))
sourceDir := "."
if len(c.Args()) >= 1 {
sourceDir = c.Args().First()
}
p, err := build.BuildPackage(sourceDir)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = p.SaveToDir(outputDir)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = generateIndex(filepath.Join(home, "/.dpm/cache/"),
filepath.Join(home, "/.dpm/index/"))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
packageSpec, err := p.Spec()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(packageSpec.Name)
}