예제 #1
0
파일: cli.go 프로젝트: TechMantra/focus
func setBasicInfos(app *cli.App, appName string, version string) {
	app.Name = appName
	app.Version = version
	app.Usage = "Focus on your tasks and let your code flow."
	t := time.Now()
	app.Copyright = "TechMantra - " + strconv.Itoa(t.Year())
}
예제 #2
0
func describeApp(app *cli.App, version string) {
	app.Name = "init-exporter"
	app.Usage = "exports services described by Procfile to systemd"
	app.Version = version

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "n, appname",
			Usage: "Application name (This name only affects the names of generated files)",
		},
		cli.BoolFlag{
			Name:  "c, uninstall",
			Usage: "Remove scripts and helpers for a particular application",
		},
		cli.StringFlag{
			Name:  "config",
			Value: defaultConfigPath,
			Usage: "path to configuration file",
		},
		cli.StringFlag{
			Name:  "p, procfile",
			Usage: "path to procfile",
		},
		cli.StringFlag{
			Name:  "f, format",
			Usage: "Format of init files (upstart | systemd)",
		},
	}
}
예제 #3
0
파일: qs.go 프로젝트: qSlide/qslide
func main() {
	var app *cli.App
	app = cli.NewApp()
	app.Name = APP_NAME
	app.Version = APP_VER
	app.Usage = "email for mail sending, or web or none for run web interface!"
	app.Commands = []cli.Command{
		task.CmdWeb,
		task.CmdEmail,
	}
	app.Flags = append(app.Flags, []cli.Flag{}...)

	app.Run(os.Args)
}
예제 #4
0
파일: main.go 프로젝트: bookerzzz/awsutils
func main() {
	var app *cli.App
	app = cli.NewApp()
	app.Name = "awsutils"
	app.Usage = "automation of Amazon Web Services configurations through their API"
	app.EnableBashCompletion = true
	app.Commands = []cli.Command{
		{
			Name:  "iam",
			Usage: "use the AWS iam API",
			Subcommands: []cli.Command{
				{
					Name:  "certs",
					Usage: "summarise certificate configurations available in your AWS account",
					Action: func(c *cli.Context) {
						out, err := exec.Command("aws", "iam", "list-server-certificates").Output()
						if err != nil {
							fmt.Println(err.Error())
							return
						}

						var r ListServerCertificatesResponse
						err = json.Unmarshal(out, &r)
						if err != nil {
							fmt.Println(err.Error())
							return
						}

						w := tabwriter.NewWriter(os.Stdout, 0, 4, 3, ' ', 0)
						fmt.Fprint(w, "ID\tName\tStatus\n")
						for _, cm := range r.ServerCertificateMetadataList {
							fmt.Fprintf(w, "%s\t%s\t%s\n", cm.ServerCertificateID, cm.ServerCertificateName, ResolveStatus(cm.Expiration))
						}
						w.Flush()
						// fmt.Printf("%+v\n", r)
					},
				},
			},
		},
		{
			Name:    "cloudfront",
			Aliases: []string{"cf"},
			Usage:   "use the AWS cloudfront API",
			Subcommands: []cli.Command{
				{
					Name:  "export-configs",
					Usage: "export the cloudfront distribution configurations",
					Action: func(c *cli.Context) {
						out, err := exec.Command("aws", "cloudfront", "list-distributions").Output()
						if err != nil {
							fmt.Println(err.Error())
							return
						}

						var r CloudFrontListDistributionsResponse
						err = json.Unmarshal(out, &r)
						if err != nil {
							fmt.Println(err.Error())
							return
						}

						w := tabwriter.NewWriter(os.Stdout, 0, 4, 3, ' ', 0)
						fmt.Fprint(w, "DomainName\n")
						for _, d := range r.Distributionlist.Items {
							fmt.Fprintf(w, "%+v\n", d.Origins.Items[0]["DomainName"])
							json, _ := json.MarshalIndent(d, "", "  ")

							fn := fmt.Sprintf("%s.json", d.Origins.Items[0]["Id"])
							f, err := os.Create(fn)
							if err != nil {
								cwd, _ := os.Getwd()
								fmt.Printf("Unable to create file '%s' in '%s'", fn, cwd)
								continue
							}
							f.Write(json)
							f.Close()
						}
						w.Flush()
					},
				},
				{
					Name:  "dists",
					Usage: "summarize the cloudfront distribution configurations",
					Flags: []cli.Flag{
						cli.StringFlag{
							Name:  "order-by",
							Value: "alias",
							Usage: "sort results on alias|origin|status",
						},
						cli.BoolFlag{
							Name:  "csv",
							Usage: "output as csv",
						},
					},
					Action: func(c *cli.Context) {
						out, err := exec.Command("aws", "cloudfront", "list-distributions").Output()
						if err != nil {
							fmt.Println(err.Error())
							return
						}

						var r CloudFrontListDistributionsResponse
						err = json.Unmarshal(out, &r)
						if err != nil {
							fmt.Println(err.Error())
							return
						}

						var list []DistSummary
						for _, d := range r.Distributionlist.Items {
							id := d.ID
							distDomain := d.DomainName
							status := d.Status
							origin := ""
							alias := ""

							if len(d.Origins.Items) > 0 {
								for _, o := range d.Origins.Items {
									if op, ok := o["OriginPath"].(string); ok && op == "" {
										origin = o["DomainName"].(string)
									}
								}
							}
							if len(d.Aliases.Items) > 0 {
								alias = strings.Join(d.Aliases.Items, ",")
							}

							list = append(list, DistSummary{ID: id, Domain: distDomain, Alias: alias, Origin: origin, Status: status})
						}

						switch c.String("order-by") {
						case "origin":
							sort.Sort(ByOrigin(list))
						case "status":
							sort.Sort(ByStatus(list))
						case "alias":
							sort.Sort(ByAlias(list))
						default:
							fmt.Println("Unrecognised value for", c.String("order-by"), ". Sorting by alias instead.")
							sort.Sort(ByAlias(list))
						}

						if c.Bool("csv") {
							fmt.Println("ID;Domain;Alias;Origin;Status")
							for _, s := range list {
								fmt.Printf(`"%s";"%s";"%s";"%s";"%s"`, s.ID, s.Domain, s.Alias, s.Origin, s.Status)
								fmt.Println()
							}
						} else {
							w := tabwriter.NewWriter(os.Stdout, 0, 4, 3, ' ', 0)
							fmt.Fprint(w, "ID\tDomain\tAlias\tOrigin\tStatus\n")
							for _, s := range list {
								fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", s.ID, s.Domain, s.Alias, s.Origin, s.Status)
							}
							w.Flush()
						}
					},
				},
			},
		},
	}

	app.Run(os.Args)
}