Exemplo n.º 1
0
Arquivo: main.go Projeto: ebenoist/ply
func Action(c *cli.Context) {
	if len(c.Args()) < 1 {
		fmt.Println("ERROR: Please specify a a task\n\n")
		cli.ShowAppHelp(c)
		return
	}

	task := c.Args()[0]

	tplVars := c.GlobalString("vars")
	cfgPath := c.GlobalString("config")
	env := c.GlobalString("environment")
	host := c.GlobalString("host")

	vars := parseVars(tplVars)
	file, err := ioutil.ReadFile(cfgPath)
	if err != nil {
		fmt.Printf("ERROR: could not find the config file: %s\n\n", cfgPath)
		cli.ShowAppHelp(c)
		return
	}

	cfg := LoadConfig(file, vars, env)
	if host != "" {
		Run(task, []string{host}, cfg)
	} else {
		Run(task, cfg.DeployEnvs[env].Hosts, cfg)
	}
}
Exemplo n.º 2
0
// GetCmd extracts cmd from command line
func GetCmd(c *cli.Context) (cmd string) {
	argc := len(c.Args())
	if argc >= 2 {
		if cl.fifoFile == "" || argc > 2 {
			fmt.Println("Too Many Arguments (Command Must Be the Last One Parameter) !")
			cli.ShowAppHelp(c)
			os.Exit(1)
		}
	loop:
		for _, arg := range c.Args() {
			if arg != cl.fifoFile {
				cmd = arg
				break loop
			}
		}
	} else if argc == 1 && c.Args()[0] == cl.fifoFile || argc == 0 {
		cmd = getPipe(PIPEUSEDBYCMD)
		return
		fmt.Println("Command Must Be the Last One Parameter!")
		cli.ShowAppHelp(c)
		os.Exit(1)
	} else {
		cmd = c.Args()[argc-1]
	}
	return
}
func runApp(c *cli.Context) {
	uri := "amqp://*****:*****@" + c.String("server") + ":5672"

	queueName := queueBaseName
	queueDurability := c.Bool("durable")

	if c.String("queuesuffix") != "" {
		queueName = fmt.Sprintf("%s-%s", queueBaseName, c.String("queuesuffix"))
	}

	if c.Int("consumer") > -1 && c.Int("producer") != 0 {
		fmt.Println("Error: Cannot specify both producer and consumer options together")
		fmt.Println()
		cli.ShowAppHelp(c)
		os.Exit(1)
	} else if c.Int("consumer") > -1 {
		fmt.Println("Running in consumer mode")
		config := ConsumerConfig{uri, c.Bool("quiet")}
		makeConsumers(config, queueName, queueDurability, c.Int("concurrency"), c.Int("consumer"))
	} else if c.Int("producer") != 0 {
		fmt.Println("Running in producer mode")
		config := ProducerConfig{uri, c.Bool("quiet"), c.Int("bytes"), c.Bool("wait-for-ack")}
		makeProducers(config, queueName, queueDurability, c.Int("concurrency"), c.Int("producer"), c.Int("wait"))
	} else {
		cli.ShowAppHelp(c)
		os.Exit(0)
	}
}
Exemplo n.º 4
0
func run(c *cli.Context) {

	user := c.String("User")
	if 0 == len(user) {
		cli.ShowAppHelp(c)
		log.Fatal("User must be provided")
	}

	text := c.String("Text")
	if 0 == len(text) {
		cli.ShowAppHelp(c)
		log.Fatal("Text must be provided")
	}

	amqpUri := c.String("AmqpUri")
	amqpExchange := c.String("AmqpExchange")
	amqpType := "direct"
	key := c.String("AmqpKey")
	amqpService := xmpptoamqp.NewAmqpService(&amqpUri, nil, nil, nil)
	amqpService.ExchangeDeclare(&amqpExchange, &amqpType)
	amqpService.Send(&amqpExchange, &key, &user, &text)

	log.WithFields(log.Fields{
		"user": c.String("User"),
	}).Info("Chat sent")

}
Exemplo n.º 5
0
func main() {
	cli.AppHelpTemplate = AppHelpTemplate
	cli.CommandHelpTemplate = CommandHelpTemplate
	cli.SubcommandHelpTemplate = SubcommandHelpTemplate
	cli.VersionPrinter = printVersion

	app := cli.NewApp()
	app.Name = "buildkite-agent"
	app.Version = agent.Version()
	app.Commands = []cli.Command{
		clicommand.AgentStartCommand,
		{
			Name:  "artifact",
			Usage: "Upload/download artifacts from Buildkite jobs",
			Subcommands: []cli.Command{
				clicommand.ArtifactUploadCommand,
				clicommand.ArtifactDownloadCommand,
				clicommand.ArtifactShasumCommand,
			},
		},
		{
			Name:  "meta-data",
			Usage: "Get/set data from Buildkite jobs",
			Subcommands: []cli.Command{
				clicommand.MetaDataSetCommand,
				clicommand.MetaDataGetCommand,
				clicommand.MetaDataExistsCommand,
			},
		},
		{
			Name:  "pipeline",
			Usage: "Make changes to the pipeline of the currently running build",
			Subcommands: []cli.Command{
				clicommand.PipelineUploadCommand,
			},
		},
		clicommand.BootstrapCommand,
	}

	// When no sub command is used
	app.Action = func(c *cli.Context) {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	// When a sub command can't be found
	app.CommandNotFound = func(c *cli.Context, command string) {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	app.Run(os.Args)
}
Exemplo n.º 6
0
func common(c *cli.Context) error {
	if c.GlobalString("seed") == "" {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}
	if c.GlobalInt("sequence") == 0 {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}
	key = parseSeed(c.String("seed"))
	return nil
}
Exemplo n.º 7
0
func ServiceMaint(c *cli.Context) {
	// Get client
	cfg, err := NewAppConfig(c)
	if err != nil {
		log.Errorf("Failed to get client: %v", err)
		return
	}
	action := c.Args().First()
	service := c.Args().Tail()[0]
	reason := ""

	if len(c.Args().Tail()) > 1 {
		reason = c.Args().Tail()[1]
	}

	switch action {
	case "enable":
		if err = cfg.client.Agent().EnableServiceMaintenance(service, reason); err != nil {
			log.Errorf("Error setting maintenance mode: %v", err)
			return
		}
	case "disable":
		if err = cfg.client.Agent().DisableServiceMaintenance(service); err != nil {
			log.Errorf("Error disabling maintenance mode: %v", err)
			return
		}
	default:
		cli.ShowAppHelp(c)
		return
	}

	log.Println("Success")
}
Exemplo n.º 8
0
Arquivo: app.go Projeto: sbinet/gotask
func NewApp() *cli.App {
	cmds, err := parseCommands()
	if err != nil {
		log.Fatal(err)
	}

	app := cli.NewApp()
	app.Name = "gotask"
	app.Usage = "Build tool in Go"
	app.Version = Version
	app.Commands = cmds
	app.Flags = []cli.Flag{
		compileFlag{Usage: "compile the task binary to pkg.task but do not run it"},
	}
	app.Action = func(c *cli.Context) {
		if c.Bool("c") || c.Bool("compile") {
			err := compileTasks()
			if err != nil {
				log.Fatal(err)
			}

			return
		}

		if len(c.Args()) == 0 {
			cli.ShowAppHelp(c)
		}
	}

	return app
}
Exemplo n.º 9
0
// GenerateDoc generating new documentation
func GenerateDoc(c *cli.Context) {
	md := c.String("input")
	html := c.String("output")
	t := c.String("template")
	path := c.String("path")
	sidebar := c.String("sidebar")

	if md == "" {
		cli.ShowAppHelp(c)
		return
	}

	fmt.Println("Begin generate")
	sb, _ := NewSidebar(sidebar)
	parent := &Dir{sidebar: sb}

	dir, err := NewDir(md, html, t, path)
	if err != nil {
		fmt.Printf("Error read dir %s\n \t%s\n", dir.mdDir, err.Error())
	}
	err = dir.read()

	if err != nil {
		fmt.Printf("Error read dir %s\n \t%s\n", dir.mdDir, err.Error())
	}
	err = dir.write(parent)

	if err != nil {
		fmt.Printf("Error write dir %s\n", dir.htmlDir)
	}

	fmt.Println("End generate")
}
Exemplo n.º 10
0
func ToggleMaintenanceMode(c *cli.Context) {
	cfg, err := NewAppConfig(c)
	if err != nil {
		log.Errorf("Failed to get client: %v", err)
		return
	}

	action := c.Args().First()

	switch action {
	case "enable":
		if err = cfg.client.Agent().EnableNodeMaintenance(c.String("reason")); err != nil {
			log.Errorf("Could not set maintenance mode: %v", err)
			return
		}
	case "disable":
		if err = cfg.client.Agent().DisableNodeMaintenance(); err != nil {
			log.Errorf("Could not unset maintenance mode: %v", err)
			return
		}
	default:
		log.Warningf("Must choose either enable or disable")
		cli.ShowAppHelp(c)
		return
	}
	log.Println("Success")
}
Exemplo n.º 11
0
Arquivo: seita.go Projeto: ilkka/seita
func main() {
	app := cli.NewApp()
	app.Name = "seita"
	app.Usage = "Enshrine and retrieve project skeletons"
	app.EnableBashCompletion = true
	app.Authors = []cli.Author{
		{
			Name:  "Ilkka Laukkanen",
			Email: "*****@*****.**",
		},
	}
	app.Commands = []cli.Command{
		{
			Name:    "put",
			Aliases: []string{"p"},
			Usage:   "Offer up this project as a skeleton",
			Action:  command.Put,
		},
		{
			Name:    "make",
			Aliases: []string{"m"},
			Usage:   "Make a new project based on a skeleton",
			Action:  command.Make,
			Before:  requireArgs("get", 1),
		},
		{
			Name:    "config",
			Aliases: []string{"c"},
			Usage:   "Manipulate configuration",
			Subcommands: []cli.Command{
				{
					Name:    "set",
					Aliases: []string{"s"},
					Usage:   "Set configuration variable value",
					Action:  config.Set,
					Before:  requireArgs("set", 2),
				},
				{
					Name:    "get",
					Aliases: []string{"g"},
					Usage:   "Get configuration variable value",
					Action:  config.Get,
					Before:  requireArgs("get", 1),
				},
				{
					Name:    "list",
					Aliases: []string{"l"},
					Usage:   "List configuration variables",
					Action:  config.List,
				},
			},
		},
	}

	app.Action = func(c *cli.Context) {
		cli.ShowAppHelp(c)
	}

	app.RunAndExitOnError()
}
Exemplo n.º 12
0
func UpdateACL(c *cli.Context) {
	if len(c.String("id")) > 1 {
		log.Errorln("--id is required!")
		cli.ShowAppHelp(c)
		return
	}

	cfg, err := NewAppConfig(c)
	if err != nil {
		log.Errorf("Failed to get client: %v", err)
		return
	}

	_, err = cfg.client.ACL().Update(&api.ACLEntry{
		Name:  c.String("name"),
		Type:  c.String("type"),
		Rules: c.Args().First(),
		ID:    c.String("id"),
	}, cfg.writeOpts)

	if err != nil {
		log.Errorf("Could not update ACL: %v", err)
		return
	}

	fmt.Println("Success")
}
Exemplo n.º 13
0
func getOpts(context *cli.Context) (string, string, string, string, string) {
	etcdURI := context.String("etcd-uri")
	redisURI := context.String("redis-uri")
	redisQueue := context.String("redis-queue")
	deployStateUri := context.String("deploy-state-uri")
	cluster := context.String("cluster")

	if etcdURI == "" || redisURI == "" || redisQueue == "" || deployStateUri == "" || cluster == "" {
		cli.ShowAppHelp(context)

		if etcdURI == "" {
			color.Red("  Missing required flag --etcd-uri or GOVERNATOR_ETCD_URI")
		}
		if redisURI == "" {
			color.Red("  Missing required flag --redis-uri or GOVERNATOR_REDIS_URI")
		}
		if redisQueue == "" {
			color.Red("  Missing required flag --redis-queue or GOVERNATOR_REDIS_QUEUE")
		}
		if deployStateUri == "" {
			color.Red("  Missing required flag --deploy-state-uri or DEPLOY_STATE_URI")
		}
		if cluster == "" {
			color.Red("  Missing required flag --cluster or CLUSTER")
		}
		os.Exit(1)
	}

	return etcdURI, redisURI, redisQueue, deployStateUri, cluster
}
Exemplo n.º 14
0
func errExit(ctx *cli.Context, err error, help bool) {
	fmt.Fprintf(os.Stderr, "\nError: %v\n\n", err)
	if help {
		cli.ShowAppHelp(ctx)
	}
	os.Exit(1)
}
Exemplo n.º 15
0
func main() {
	app := cli.NewApp()
	app.Name = "rabbitmq-cli-consumer"
	app.Usage = "Consume RabbitMQ easily to any cli program"
	app.Author = "Richard van den Brand"
	app.Email = "*****@*****.**"
	app.Version = "1.1.0"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "executable, e",
			Usage: "Location of executable",
		},
		cli.StringFlag{
			Name:  "configuration, c",
			Usage: "Location of configuration file",
		},
		cli.BoolFlag{
			Name:  "verbose, V",
			Usage: "Enable verbose mode (logs to stdout and stderr)",
		},
	}
	app.Action = func(c *cli.Context) {
		if c.String("configuration") == "" && c.String("executable") == "" {
			cli.ShowAppHelp(c)
			os.Exit(1)
		}

		verbose := c.Bool("verbose")

		logger := log.New(os.Stderr, "", log.Ldate|log.Ltime)
		cfg, err := config.LoadAndParse(c.String("configuration"))

		command.Cconf = cfg

		if err != nil {
			logger.Fatalf("Failed parsing configuration: %s\n", err)
		}

		errLogger, err := createLogger(cfg.Logs.Error, verbose, os.Stderr)
		if err != nil {
			logger.Fatalf("Failed creating error log: %s", err)
		}

		infLogger, err := createLogger(cfg.Logs.Info, verbose, os.Stdout)
		if err != nil {
			logger.Fatalf("Failed creating info log: %s", err)
		}

		factory := command.Factory(c.String("executable"))

		client, err := consumer.New(cfg, factory, errLogger, infLogger)
		if err != nil {
			errLogger.Fatalf("Failed creating consumer: %s", err)
		}

		client.Consume()
	}

	app.Run(os.Args)
}
Exemplo n.º 16
0
func GetKvKey(c *cli.Context) {
	if !c.Args().Present() {
		cli.ShowAppHelp(c)
		return
	}

	// Get client
	cfg, err := NewAppConfig(c)
	if err != nil {
		log.Errorf("Failed to get client: %v", err)
		return
	}

	kv := cfg.client.KV()
	var results []*api.KVPair
	for _, a := range append([]string{c.Args().First()}, c.Args().Tail()...) {
		if c.Bool("recurse") {
			pairs, _, err := kv.List(a, cfg.queryOpts)
			if err != nil {
				log.Debugf("Could not list keys: %v", err)
				continue
			}

			for _, p := range pairs {
				results = append(results, p)
			}
			continue
		}

		pair, _, err := kv.Get(a, cfg.queryOpts)
		if err != nil {
			log.Debugf("Could not retrieve key: %v", err)
			continue
		}
		if pair != nil {
			results = append(results, pair)
		}
	}

	if len(results) > 0 {
		if c.GlobalBool("verbose") {
			for _, r := range results {
				bytes, err := marshalPrettyKey(r)
				if err != nil {
					log.Debugf("Could not marshal JSON: %v\n", err)
				}
				fmt.Println(string(bytes))
			}
			return
		}

		for _, r := range results {
			fmt.Printf("%s\n", r.Value)
		}

		return
	}

	log.Errorln("Key not found")
}
Exemplo n.º 17
0
func FireEvent(c *cli.Context) {
	if len(c.Args().First()) < 1 || len(c.Args().Tail()) < 1 {
		log.Errorln("name and payload are required")
		cli.ShowAppHelp(c)
		return
	}
	cfg, err := NewAppConfig(c)
	if err != nil {
		log.Errorf("Failed to get client: %v", err)
		return
	}

	event := &api.UserEvent{
		Name:          c.Args().First(),
		Payload:       []byte(c.Args().Tail()[0]),
		NodeFilter:    c.String("node"),
		ServiceFilter: c.String("service"),
		TagFilter:     c.String("tag"),
	}
	eid, _, err := cfg.client.Event().Fire(event, cfg.writeOpts)

	if err != nil {
		log.Errorf("Could not fire event: %v", err)
		return
	}
	fmt.Println(eid)
}
Exemplo n.º 18
0
func main() {
	app := cli.NewApp()
	cli.AppHelpTemplate = appHelpTemplate
	app.Name = "multic"
	app.Version = "0.0.5"
	app.Usage = "Run shell commands in multiple directories."
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "list, l",
			Usage: "list configured directory groups",
		},
		cli.StringSliceFlag{
			Name:  "group, g",
			Value: &cli.StringSlice{},
			Usage: "specify a directory group",
		},
		cli.StringFlag{
			Name:  "configuration, c",
			Value: "~/.multic/config",
			Usage: "specify a configuration file",
		},
	}
	app.Action = func(ctx *cli.Context) {
		args := ctx.Args()
		config := config.LoadConfig(ctx.String("configuration"))
		if ctx.IsSet("list") {
			printDirectoryGroups(config)
		} else if len(args) == 0 {
			cli.ShowAppHelp(ctx)
		} else {
			run(config, ctx.StringSlice("group"), args)
		}
	}
	app.Run(os.Args)
}
Exemplo n.º 19
0
func main() {
	app := cli.NewApp()
	app.Name = "swarm-bench"
	app.Usage = "Swarm Benchmarking Tool"
	app.Version = "0.1.0"
	app.Author = ""
	app.Email = ""
	app.Flags = []cli.Flag{
		cli.IntFlag{
			Name:  "concurrency, c",
			Value: 1,
			Usage: "Number of multiple requests to perform at a time. Default is one request at a time.",
		},
		cli.IntFlag{
			Name:  "requests, n",
			Value: 1,
			Usage: "Number of containers to start for the benchmarking session. The default is to just start a single container.",
		},
		cli.StringFlag{
			Name:  "image, i",
			Usage: "Image to use for benchmarking.",
		},
	}

	app.Action = func(c *cli.Context) {
		if c.String("image") == "" {
			cli.ShowAppHelp(c)
			os.Exit(1)
		}
		bench(c.Int("requests"), c.Int("concurrency"), c.String("image"))
	}

	app.Run(os.Args)
}
Exemplo n.º 20
0
Arquivo: main.go Projeto: pdf/crononag
func run(c *cli.Context) {
	args := c.Args()
	if len(c.Args()) == 0 {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	doSplay(c)

	suppressRegexpSlice := make(regexpSlice, len(c.StringSlice(`suppress-regexp`)))
	for i, s := range c.StringSlice(`suppress-regexp`) {
		suppressRegexpSlice[i] = regexp.MustCompile(s)
	}

	forceRegexpSlice := make(regexpSlice, len(c.StringSlice(`force-regexp`)))
	for i, s := range c.StringSlice(`force-regexp`) {
		forceRegexpSlice[i] = regexp.MustCompile(s)
	}

	var cmd *exec.Cmd
	if len(args) > 1 {
		cmd = exec.Command(args[0], args[1:len(args)]...)
	} else {
		cmd = exec.Command(args[0])
	}

	doCmd(c, cmd, forceRegexpSlice, suppressRegexpSlice)
}
Exemplo n.º 21
0
func domainRecordCreate(ctx *cli.Context) {
	if len(ctx.Args()) < 2 {
		cli.ShowAppHelp(ctx)
		fmt.Printf("Invalid arguments.\n")
		os.Exit(1)
	}

	client := apiv2.NewClient(APIKey)

	domainRecord := client.NewDomainRecord()
	domainRecord.Name = ctx.Args().First()
	domainRecord.Data = ctx.Args()[1]
	domainRecord.Type = strings.ToUpper(ctx.String("type"))

	if domainRecord.Type == "MX" || domainRecord.Type == "SRV" {
		domainRecord.Priority = ctx.Int("priority")
	}
	if domainRecord.Type == "SRV" {
		domainRecord.Port = ctx.Int("port")
		domainRecord.Weight = ctx.Int("weight")
	}

	domain, err := client.FindDomainFromName(domainRecord.Name)
	if err != nil {
		fmt.Printf("%s\n", err)
	}

	domainRecord, createErr := client.CreateDomainRecord(domainRecord, domain)
	if createErr != nil {
		fmt.Printf("%s\n", createErr)
		os.Exit(1)
	}

	WriteOutput(domainRecord)
}
Exemplo n.º 22
0
func printTemplates(c *cli.Context) {
	args := c.Args()
	output := c.App.Writer

	if len(args) == 0 {
		cli.ShowAppHelp(c)
	}

	var wg sync.WaitGroup
	contents := make(chan string)
	for _, candidate := range args {
		wg.Add(1)
		go func(candidate string) {
			defer wg.Done()
			candidate = upperFirstChar(candidate)
			content := tryGetTemplate(candidate)

			if content != "" {
				contents <- fmt.Sprintf("# %s\n%s", candidate, content)
			}
		}(candidate)
	}
	go func() {
		wg.Wait()
		close(contents)
	}()

	for content := range contents {
		fmt.Fprintln(output, content)
	}
}
Exemplo n.º 23
0
func CmdImport(c *cli.Context) {
	var file string
	var err error
	if file = c.String("file"); file == "" {
		fmt.Println("file flag missing")
		cli.ShowAppHelp(c)
		return
	}

	data, err := ioutil.ReadFile(file)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	importer := api.ImportCreate()
	kibanaData, err := api.Parse(data)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	err = importer.All(api.Create(c.String("uri")), kibanaData)

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println("Import successful...")
}
Exemplo n.º 24
0
func getdestination(c *cli.Context) (string, string, error) {
	var mxServer string
	var targetAddress string
	var err error
	myArgs := c.Args()
	if len(myArgs) == 0 {
		cli.ShowAppHelp(c)
		os.Exit(130)
	}
	debugprint("Entering getdestination \n")
	if len(myArgs) > 1 {
		if myArgs[1][:1] != "@" {
			mxServer = ""
			targetAddress = ""
			err = fmt.Errorf("Server argument should be like \"@server\" %q provided", myArgs[1])
		} else {
			mxServer = myArgs[1][1:]
			targetAddress = myArgs[0]
		}
	} else {
		targetAddress = myArgs[0]
		mxServer, err = resolvmx(strings.SplitAfter(targetAddress, "@")[1])
		if err != nil {
			mxServer = ""
		}
	}
	debugprint(fmt.Sprintf("Target address is %s, mxServer is %s, error is %v \n",
		targetAddress, mxServer, err))

	return targetAddress, mxServer, err
}
Exemplo n.º 25
0
func Contrib(c *cli.Context) {
	if len(c.Args()) == 0 {
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	names, err := getContributors(c.Args())
	if err != nil {
		log.Fatal(err)
	}

	number := c.Int("number")
	if number == 0 {
		number = 1
	}

	for i, name := range names {
		if i >= number {
			break
		}
		fmt.Println(name)
	}

	os.Exit(0)
}
Exemplo n.º 26
0
func main() {
	app := cli.NewApp()
	app.Name = "runc"
	app.Usage = usage
	app.Version = version
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "id",
			Value: getDefaultID(),
			Usage: "specify the ID to be used for the container",
		},
		cli.BoolFlag{
			Name:  "debug",
			Usage: "enable debug output for logging",
		},
		cli.StringFlag{
			Name:  "root",
			Value: "/var/run/ocf",
			Usage: "root directory for storage of container state (this should be located in tmpfs)",
		},
		cli.StringFlag{
			Name:  "criu",
			Value: "criu",
			Usage: "path to the criu binary used for checkpoint and restore",
		},
	}
	app.Commands = []cli.Command{
		checkpointCommand,
		eventsCommand,
		restoreCommand,
		specCommand,
	}
	app.Before = func(context *cli.Context) error {
		if context.GlobalBool("debug") {
			logrus.SetLevel(logrus.DebugLevel)
		}
		return nil
	}
	// default action is to execute a container
	app.Action = func(context *cli.Context) {
		if os.Geteuid() != 0 {
			cli.ShowAppHelp(context)
			logrus.Fatal("runc should be run as root")
		}
		spec, err := loadSpec(context.Args().First())
		if err != nil {
			fatal(err)
		}
		status, err := execContainer(context, spec)
		if err != nil {
			fatal(err)
		}
		// exit with the container's exit status so any external supervisor is
		// notified of the exit with the correct exit status.
		os.Exit(status)
	}
	if err := app.Run(os.Args); err != nil {
		logrus.Fatal(err)
	}
}
Exemplo n.º 27
0
func init() {

	App.Name = "ha"
	App.Usage = "HsoubAcademy command line tool, Ha!"
	App.Author = "HsoubAcademy Team"
	App.Email = "*****@*****.**"
	App.Version = "0.0.1"

	App.Commands = []cli.Command{
		{
			Name:    "parse",
			Aliases: []string{"p"},
			Flags: []cli.Flag{
				cli.BoolFlag{
					Name:  "s, stats",
					Usage: "Count words and show external links.",
				},
			},
			Usage:  "Parse a Markdown file",
			Action: RenderWrapper,
		},
	}

	App.Action = func(c *cli.Context) {

		if IsFile(c.Args().First()) {
			RenderWrapper(c)
		} else {
			cli.ShowAppHelp(c)
		}

	}
}
Exemplo n.º 28
0
func setDefaultAction(app *cli.App) {
	app.Action = func(c *cli.Context) {
		// TODO: If in a focused directory show the list of tasks
		// If not show the app help or some basic direction to init it
		cli.ShowAppHelp(c)
	}
}
Exemplo n.º 29
0
func runApp(c *cli.Context) {
	debug := c.Bool("debug")

	if err := validateCLI(c); err != nil {
		log.Println("CLI Validation Error:", err)
		cli.ShowAppHelp(c)
		os.Exit(1)
	}

	if !debug {
		TurnOffLogging()
	}

	var sitemap *domain.Sitemap
	if useSavedResults(c) {
		sitemap = runSitemapLoader(c)
	} else {
		sitemap = runSitemapBuilder(c)
	}

	if sitemap == nil {
		fmt.Println("Could not build Sitemap")
		return
	}

	outputSitemapToConsole(c, sitemap)

	if shouldSaveResults(c) {
		outputSitemapToFile(c, sitemap)
	}
}
Exemplo n.º 30
0
func RunAction(c *cli.Context) error {
	config.GrpcPort = c.Int("port")
	config.Debug = c.Bool("debug")
	config.TlsCertFile = c.String("tls-cert-file")
	config.TlsKeyFile = c.String("tls-key-file")
	config.ClientID = c.String("client-id")
	config.ClientSecret = c.String("client-secret")
	config.AuthDiscovery = c.String("discovery")
	config.RedisAddr = c.String("redis-addr")
	config.RedisDB = c.Int("redis-db")
	config.RedisPassword = c.String("redis-password")
	config.RedisMasterName = c.String("redis-master")
	config.RedisSentinel = c.Bool("redis-sentinel")
	storage := c.String("storage")

	if config.Debug {
		log.SetLevel(log.DebugLevel)
	}

	if storage == "" || storage == "none" {
		cli.ShowAppHelp(c)
		return errors.New("storage is not set")
	}
	driver := drivers.GetDriver(storage)
	if driver == nil {
		return fmt.Errorf("main.go: storage driver '%s' not found\n", storage)
	}

	s, err := driver.New(c)
	if err != nil {
		return fmt.Errorf("main.go: error while creating new storage driver: %v", err)
	}
	srv := listener.NewServer(config, s)
	return srv.ListenGRPC()
}