mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 09:27:50 +00:00
feat: adding new export format
This commit is contained in:
@@ -16,10 +16,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FormatDotenv string = "dotenv"
|
FormatDotenv string = "dotenv"
|
||||||
FormatJson string = "json"
|
FormatJson string = "json"
|
||||||
FormatCSV string = "csv"
|
FormatCSV string = "csv"
|
||||||
FormatYaml string = "yaml"
|
FormatYaml string = "yaml"
|
||||||
|
FormatDotEnvExport string = "dotenv-export"
|
||||||
)
|
)
|
||||||
|
|
||||||
// exportCmd represents the export command
|
// exportCmd represents the export command
|
||||||
@@ -85,6 +86,8 @@ func formatEnvs(envs []models.SingleEnvironmentVariable, format string) (string,
|
|||||||
switch strings.ToLower(format) {
|
switch strings.ToLower(format) {
|
||||||
case FormatDotenv:
|
case FormatDotenv:
|
||||||
return formatAsDotEnv(envs), nil
|
return formatAsDotEnv(envs), nil
|
||||||
|
case FormatDotEnvExport:
|
||||||
|
return formatAsDotEnvExport(envs), nil
|
||||||
case FormatJson:
|
case FormatJson:
|
||||||
return formatAsJson(envs), nil
|
return formatAsJson(envs), nil
|
||||||
case FormatCSV:
|
case FormatCSV:
|
||||||
@@ -117,6 +120,15 @@ func formatAsDotEnv(envs []models.SingleEnvironmentVariable) string {
|
|||||||
return dotenv
|
return dotenv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format environment variables as a dotenv file with export at the beginning
|
||||||
|
func formatAsDotEnvExport(envs []models.SingleEnvironmentVariable) string {
|
||||||
|
var dotenv string
|
||||||
|
for _, env := range envs {
|
||||||
|
dotenv += fmt.Sprintf("export %s='%s'\n", env.Key, env.Value)
|
||||||
|
}
|
||||||
|
return dotenv
|
||||||
|
}
|
||||||
|
|
||||||
func formatAsYaml(envs []models.SingleEnvironmentVariable) string {
|
func formatAsYaml(envs []models.SingleEnvironmentVariable) string {
|
||||||
var dotenv string
|
var dotenv string
|
||||||
for _, env := range envs {
|
for _, env := range envs {
|
||||||
|
|||||||
Reference in New Issue
Block a user