-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(expand): Add "expand" (env vars expansion) functionality (string…
…s only)
- Loading branch information
1 parent
1db025d
commit bc357ee
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package expand | ||
|
||
import ( | ||
"github.com/sikalabs/slut/cmd/root" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "expand", | ||
Short: "Expand environment variables in files and strings", | ||
} | ||
|
||
func init() { | ||
root.RootCmd.AddCommand(Cmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package string | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
expandcmd "github.com/sikalabs/slut/cmd/expand" | ||
rootcmd "github.com/sikalabs/slut/cmd/root" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var CmdFlagSource string | ||
|
||
var Cmd = &cobra.Command{ | ||
Use: "string", | ||
Short: "Expand environment variables in string", | ||
Args: cobra.NoArgs, | ||
Run: func(c *cobra.Command, args []string) { | ||
if rootcmd.RootCmdFlagJson { | ||
outJson, err := json.Marshal(os.ExpandEnv(CmdFlagSource)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(string(outJson)) | ||
} else { | ||
fmt.Println(os.ExpandEnv(CmdFlagSource)) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
expandcmd.Cmd.AddCommand(Cmd) | ||
Cmd.Flags().StringVarP( | ||
&CmdFlagSource, | ||
"source", | ||
"s", | ||
"", | ||
"Source template string", | ||
) | ||
Cmd.MarkFlagRequired("source") | ||
} |