Exemplo n.º 1
0
func logEnvs() error {
	environments, err := envman.ReadEnvs(envman.CurrentEnvStoreFilePath)
	if err != nil {
		return err
	}

	if len(environments) == 0 {
		log.Info("[ENVMAN] - Empty envstore")
	} else {
		for _, env := range environments {
			key, value, err := env.GetKeyValuePair()
			if err != nil {
				return err
			}

			opts, err := env.GetOptions()
			if err != nil {
				return err
			}

			envString := "- " + key + ": " + value
			log.Debugln(envString)
			if !*opts.IsExpand {
				expandString := "  " + "isExpand" + ": " + "false"
				log.Debugln(expandString)
			}
		}
	}

	return nil
}
Exemplo n.º 2
0
func run(c *cli.Context) {
	log.Debugln("[ENVMAN] - Work path:", envman.CurrentEnvStoreFilePath)

	if len(c.Args()) > 0 {
		doCmdEnvs, err := envman.ReadEnvs(envman.CurrentEnvStoreFilePath)
		if err != nil {
			log.Fatal("[ENVMAN] - Failed to load EnvStore:", err)
		}

		doCommand := c.Args()[0]

		doArgs := []string{}
		if len(c.Args()) > 1 {
			doArgs = c.Args()[1:]
		}

		cmdToExecute := CommandModel{
			Command:      doCommand,
			Environments: doCmdEnvs,
			Argumentums:  doArgs,
		}

		log.Debugln("[ENVMAN] - Executing command:", cmdToExecute)

		if exit, err := runCommandModel(cmdToExecute); err != nil {
			log.Error("[ENVMAN] - Failed to execute command:", err)
			os.Exit(exit)
		}

		log.Debugln("[ENVMAN] - Command executed")
	} else {
		log.Fatal("[ENVMAN] - No command specified")
	}
}
Exemplo n.º 3
0
func print(c *cli.Context) {
	// Input validation
	format := c.String(FormatKey)
	if format == "" {
		format = OutputFormatRaw
	} else if !(format == OutputFormatRaw || format == OutputFormatJSON) {
		log.Fatalf("Invalid format: %s", format)
	}

	expand := c.Bool(ExpandKey)

	// Read envs
	environments, err := envman.ReadEnvs(envman.CurrentEnvStoreFilePath)
	if err != nil {
		log.Fatalf("Failed to read envs, error: %s", err)
	}

	envsJSONList, err := convertToEnsJSONModel(environments, expand)
	if err != nil {
		log.Fatalf("Failed to convert envs, error: %s", err)
	}

	// Print envs
	switch format {
	case OutputFormatRaw:
		printRawEnvs(envsJSONList)
		break
	case OutputFormatJSON:
		if err := printJSONEnvs(envsJSONList); err != nil {
			log.Fatalf("Failed to print env list, err: %s", err)
		}
		break
	default:
		log.Fatalf("[STEPMAN] - Invalid format: %s", format)
	}
}