本文整理匯總了Golang中github.com/codegangsta/cli.Context.BoolT方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.BoolT方法的具體用法?Golang Context.BoolT怎麽用?Golang Context.BoolT使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.BoolT方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SecureYamlCmd
func SecureYamlCmd(c *cli.Context, client drone.Client) error {
var (
repo = c.String("repo")
inFile = c.String("in")
outFile = c.String("out")
ymlFile = c.String("yaml")
checksum = c.BoolT("checksum")
)
owner, name, err := parseRepo(repo)
if err != nil {
return err
}
keypair, err := client.RepoKey(owner, name)
if err != nil {
return err
}
key, err := toPublicKey(keypair.Public)
if err != nil {
return err
}
// read the .drone.sec.yml file (plain text)
plaintext, err := readInput(inFile)
if err != nil {
return err
}
// parse the .drone.sec.yml file
sec := new(secure.Secure)
err = yaml.Unmarshal(plaintext, sec)
if err != nil {
return err
}
// read the .drone.yml file and caclulate the
// checksum. add to the .drone.sec.yml file.
yml, err := ioutil.ReadFile(ymlFile)
if err == nil && checksum {
sec.Checksum = sha256sum(string(yml))
}
// re-marshal the .drone.sec.yml file since we've
// added the checksum
plaintext, err = yaml.Marshal(sec)
if err != nil {
return err
}
// encrypt the .drone.sec.yml file
ciphertext, err := encrypt(plaintext, key)
if err != nil {
return err
}
// write the encrypted .drone.sec.yml file to .drone.sec
return writeOutput(outFile, ciphertext)
}
示例2: serve
func serve(c *cli.Context) {
// Ensure api socket directory exists; if not, create it
apiSocket := getApiSocket(c)
if _, err := os.Stat(apiSocket); os.IsNotExist(err) {
os.MkdirAll(path.Dir(apiSocket), 0777)
}
d := dokku.New()
// If caching is enabled, create cache socket if necessary and launch cache
// server in the background
if !c.BoolT("enable-cache") {
cacheSocket := getCacheSocket(c)
if _, err := os.Stat(cacheSocket); os.IsNotExist(err) {
os.MkdirAll(path.Dir(cacheSocket), 0777)
}
go func() {
err := listenCache(d, cacheSocket)
if err != nil {
panic(err)
}
}()
}
// Start api server
err := listenAPI(d, apiSocket)
if err != nil {
panic(err)
}
}
示例3: Migrate
// Migrate runs migrations
func Migrate(ctx *cli.Context) {
if ctx.BoolT("d") {
// run migrations
migration.DropTables()
}
migration.MigrateTables()
query.PopulateDB()
}
示例4: setupGithub
// helper function to setup the GitHub remote from the CLI arguments.
func setupGithub(c *cli.Context) (remote.Remote, error) {
return github.New(github.Opts{
URL: c.String("github-server"),
Client: c.String("github-client"),
Secret: c.String("github-sercret"),
Scopes: c.StringSlice("github-scope"),
Username: c.String("github-git-username"),
Password: c.String("github-git-password"),
PrivateMode: c.Bool("github-private-mode"),
SkipVerify: c.Bool("github-skip-verify"),
MergeRef: c.BoolT("github-merge-ref"),
})
}
示例5: cmdLogsStream
func cmdLogsStream(c *cli.Context) {
_, app, err := stdcli.DirApp(c, ".")
if err != nil {
stdcli.Error(err)
return
}
err = rackClient(c).StreamAppLogs(app, c.String("filter"), c.BoolT("follow"), c.Duration("since"), os.Stdout)
if err != nil {
stdcli.Error(err)
return
}
}
示例6: getOptions
func getOptions(c *cli.Context) ([]magpie.Option, error) {
var options []magpie.Option
if c.IsSet(tagFlag) {
options = append(options, magpie.Tags(c.StringSlice(tagFlag)))
}
if c.IsSet(prefixFlag) {
options = append(options, magpie.Prefix(c.String(prefixFlag)))
}
if c.IsSet(packageNameFlag) {
options = append(options, magpie.PackageName(c.String(packageNameFlag)))
}
if c.IsSet(unsafeFlag) {
options = append(options, magpie.Unsafe(c.Bool(unsafeFlag)))
}
if c.IsSet(compressFlag) {
options = append(options, magpie.Compress(c.BoolT(compressFlag)))
}
if c.IsSet(fileModeFlag) {
fileMode := c.String(fileModeFlag)
if fileMode != "" {
n, err := strconv.ParseUint(fileMode, 10, 32)
if err != nil {
return nil, err
}
options = append(options, magpie.OverrideFileMode(uint(n)))
}
}
if c.IsSet(fileModTimeFlag) {
fileMod := c.String(fileModTimeFlag)
if fileMod != "" {
n, err := strconv.ParseInt(fileMod, 10, 64)
if err != nil {
return nil, err
}
options = append(options, magpie.OverrideFileModTime(n))
}
}
if c.IsSet(outputFlag) {
options = append(options, magpie.OutputFile(c.String(outputFlag)))
}
if c.IsSet(ignoreFlag) {
options = append(options, magpie.Ignore(c.StringSlice(ignoreFlag)))
}
return options, nil
}
示例7: server
func server(ctx *cli.Context) {
cfgFile := configName
if first := ctx.Args().First(); first != "" {
cfgFile = first
}
cfg, err := getConfig(cfgFile)
if err != nil {
fmt.Println(err)
return
}
s := hero.NewServer(cfg, &hero.SimpleTokenGen{}, nil)
if ctx.BoolT("migrate") {
s.Migrate()
}
s.Run()
}
示例8: create
func create(c *cli.Context) {
checkArgs(c)
d := dogo.Droplet{
Name: c.Args().First(),
ImageID: c.Int("image"),
SizeID: dogo.SizesMap[c.String("size")],
RegionID: dogo.RegionsMap[c.String("region")],
BackupsActive: c.BoolT("backups"),
}
keys := c.IntSlice("keys")
network := c.BoolT("network")
_, err := docli.CreateDroplet(d, keys, network)
if err != nil {
fatalf(err.Error())
}
fmt.Printf("Successfully queued %s for creation ... \n", d.Name)
}
示例9: clirun
func clirun(c *cli.Context) {
config := &Config{
Dest: c.String("dest"),
Name: c.String("name"),
Data: make(map[string]string),
OpenEditor: c.BoolT("open-editor"),
}
src := c.String("src")
if len(src) > 0 {
config.Source = &DirectorySource{Path: src}
} else {
config.Source = &GithubReleaseSource{
Tag: c.String("gh-tag"),
Owner: c.String("gh-owner"),
Repo: c.String("gh-repo"),
Name: c.String("skel"),
}
}
data := c.String("data")
if len(data) > 0 {
info, err := os.Stat(data)
if err != nil || info.IsDir() {
log.Printf("Couldn't open %s. Skipping.\n", data)
} else {
content, err := ioutil.ReadFile(data)
if err != nil {
log.Printf("Failed to read data file. Skipping. Error was: %s\n", err)
}
err = yaml.Unmarshal(content, &config.Data)
if err != nil {
log.Printf("Failed to unmarshall data file: %s.\n", err)
}
}
}
if err := Run(config); err != nil {
log.Fatal(err)
}
}
示例10: LoadConfig
func LoadConfig(ctx *cli.Context) {
var contents []byte
if _, err := os.Stat(CONFIG_FILE); err != nil && CONFIG_FILE != "/dev/null" {
fmt.Printf("Unable to find config file. Resorting to defaults.\n")
} else {
contents = handle_err(ioutil.ReadFile(CONFIG_FILE)).([]byte)
err := json.Unmarshal(contents, &RC)
if err != nil && CONFIG_FILE != "/dev/null" {
fmt.Printf("Error reading config file (%s): %v.\n", CONFIG_FILE, err)
}
}
// Override config file values with CLI options
if &RC.Host == nil || ctx.IsSet("host") {
RC.Host = ctx.String("host")
}
if &RC.Port == nil || ctx.IsSet("port") {
RC.Port = ctx.Int("port")
}
if &RC.Nick == nil || ctx.IsSet("nick") {
RC.Nick = ctx.String("nick")
}
if &RC.Channel == nil || ctx.IsSet("channel") {
RC.Channel = ctx.String("channel")
}
if &RC.SSL == nil {
RC.SSL = ctx.BoolT("insecure")
}
if &RC.Verbose == nil {
RC.Verbose = ctx.Bool("verbose")
}
RC.VTClient = govt.Client{Apikey: RC.VTAPIKey, Url: "https://www.virustotal.com/vtapi/v2/"}
}
示例11: doAlertsList
func doAlertsList(c *cli.Context) error {
conffile := c.GlobalString("conf")
filterServices := c.StringSlice("service")
filterStatuses := c.StringSlice("host-status")
client := newMackerel(conffile)
alerts, err := client.FindAlerts()
logger.DieIf(err)
joinedAlerts := joinMonitorsAndHosts(client, alerts)
for _, joinAlert := range joinedAlerts {
if len(filterServices) > 0 {
found := false
for _, filterService := range filterServices {
if joinAlert.Host != nil {
if _, ok := joinAlert.Host.Roles[filterService]; ok {
found = true
}
} else if joinAlert.Monitor.Service == filterService {
found = true
}
}
if !found {
continue
}
}
if len(filterStatuses) > 0 {
found := false
for _, filterStatus := range filterStatuses {
if joinAlert.Host != nil && joinAlert.Host.Status == filterStatus {
found = true
}
}
if !found {
continue
}
}
fmt.Println(formatJoinedAlert(joinAlert, c.BoolT("color")))
}
return nil
}
示例12: AddAttachment
func AddAttachment(c *cli.Context) {
objectId := helper.ValidId(c.Args().First())
attachmentPath := c.Args().Get(1)
object, err := data.GetObject(objectId)
helper.ErrExit(err != nil, fmt.Sprintf("Invalid object ID %s!\n", objectId))
dbFile, err := data.Files().Create("")
helper.ErrPanic(err)
file, err := os.Open(attachmentPath)
helper.ErrPanic(err)
defer file.Close()
_, err = io.Copy(dbFile, file)
helper.ErrPanic(err)
err = dbFile.Close()
helper.ErrPanic(err)
var (
content = ""
metadata = make(map[string]string)
)
if strings.ToLower(filepath.Ext(file.Name())) == ".pdf" {
if c.BoolT("extract-pdf-text") {
content, metadata, err = helper.ConvertPDF(file)
helper.ErrPanic(err)
}
}
attachment := data.CreateAttachment(dbFile, path.Base(attachmentPath), content, metadata)
object.Attachments = append(object.Attachments, *attachment)
object.Update()
fmt.Println(attachment.Id.Hex())
}
示例13: loadConfig
func loadConfig(c *cli.Context) {
if len(c.Args()) > 0 {
config_path := c.Args()[0]
_, err := toml.DecodeFile(config_path, &Config)
checkErr(err)
log.Printf("loaded configuration from %s %+v\n", config_path, Config)
}
if c.IsSet("db-log") == true {
Config.DBLog = c.Bool("db-log")
}
if c.IsSet("development") == true {
Config.Development = c.BoolT("development")
}
if c.IsSet("database") == true {
Config.DBPath = c.String("database")
}
if c.IsSet("port") == true {
Config.Port = c.Int("port")
}
}
示例14: New
// New TODO
func New(context *cli.Context) *Config {
// TODO: parse this more gracefully
loggingLevel := logrus.DebugLevel
logLevelArg := context.String(logLevel)
var err error
loggingLevel, err = logrus.ParseLevel(logLevelArg)
if err != nil {
loggingLevel = logrus.DebugLevel
}
return &Config{
ServiceName: context.String(serviceName),
ServiceVerion: context.String(serviceVersion),
EndpointHost: context.String(endpointHost),
EndpointPort: context.Int(endpointPort),
LogstashServer: context.String(logstashServer),
Register: context.BoolT(register),
Proxy: context.BoolT(proxy),
Log: context.BoolT(log),
Supervise: context.Bool(supervise),
Controller: Controller{
URL: context.String(controllerURL),
Poll: context.Duration(controllerPoll),
},
Tenant: Tenant{
ID: context.String(tenantID),
Token: context.String(tenantToken),
TTL: context.Duration(tenantTTL),
Heartbeat: context.Duration(tenantHeartbeat),
},
Registry: Registry{
URL: context.String(registryURL),
Token: context.String(registryToken),
},
Kafka: Kafka{
Username: context.String(kafkaUsername),
Password: context.String(kafkaPassword),
APIKey: context.String(kafkaToken),
RestURL: context.String(kafkaRestURL),
Brokers: context.StringSlice(kafkaBrokers),
SASL: context.Bool(kafkaSASL),
},
Nginx: Nginx{
Port: context.Int(nginxPort),
},
LogLevel: loggingLevel,
AppArgs: context.Args(),
}
}
示例15: server
func server(ctx *cli.Context) {
cfgFile := configName
if first := ctx.Args().First(); first != "" {
cfgFile = first
}
cfg, err := getConfig(cfgFile)
if err != nil {
fmt.Println(err)
return
}
s := hero.NewServer(cfg, &hero.SimpleTokenGen{}, nil)
if ctx.BoolT("dev") {
v, err := hero.NewDefaultView(cfg.TemplatesDir, true)
if err != nil {
fmt.Println(err)
return
}
s = hero.NewServer(cfg, &hero.SimpleTokenGen{}, v)
}
if ctx.BoolT("migrate") {
s.Migrate()
}
if ctx.BoolT("https") {
cert := ctx.String("cert")
_, ferr := os.Stat(cert)
if ferr != nil {
fmt.Println(ferr)
return
}
key := ctx.String("key")
_, ferr = os.Stat(cert)
if ferr != nil {
fmt.Println(ferr)
return
}
s.RunTLS(cert, key)
return
}
s.Run()
}