Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makes this more package friendly and removes cruft #13

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions cli/actions/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import (
"github.com/nqd/flat"
)

func ReadKeyCmd(configFilePath string, key string, outputFilePath string, traceOutFilePath string) (string, error) {
configurationMap, err := ReadConfigurationMap(configFilePath)

if err != nil {
return "", err
}
func ReadKeyCmd(configurationMap *ConfigurationMap, key string, outputFilePath string, traceOutFilePath string) (string, error) {

memoryMap, traces, err := ReadMemoryMap(configurationMap)

Expand Down
8 changes: 1 addition & 7 deletions cli/actions/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ import (
"github.com/nqd/flat"
)

func ReplaceCmd(configMap string, inputPath string, outputPath string, traceFileOutput string) {
configurationMap, err := ReadConfigurationMap(configMap)

if err != nil {
fmt.Println(err)
return
}
func ReplaceCmd(configurationMap *ConfigurationMap, inputPath string, outputPath string, traceFileOutput string) {

memoryMap, traces, err := ReadMemoryMap(configurationMap)

Expand Down
28 changes: 13 additions & 15 deletions cli/actions/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,28 @@ func TestReplaceCmd(t *testing.T) {
_ = afero.WriteFile(AppFs, "test.json", []byte(jsonData), 0644)
_ = afero.WriteFile(AppFs, "test.yaml", []byte(yamlData), 0644)

ConfigurationMap := `{
"version": "1.0.0",
"configs": [
ConfigurationMap := &ConfigurationMap{
Version: "1.0.0",
Configs: []Config{
{
"path": "test.json",
"mappings": [],
"applyFile": "after"
Path: "test.json",
Mappings: []Mapping{},
ApplyFile: "after",
},
{
"path": "test.yaml",
"mappings": [],
"applyFile": "after"
}
]
}`

_ = afero.WriteFile(AppFs, "config.json", []byte(ConfigurationMap), 0644)
Path: "test.yaml",
Mappings: []Mapping{},
ApplyFile: "after",
},
},
}

inputFile := "I am {{ .key }}"
outputFile := "I am key"

_ = afero.WriteFile(AppFs, "test.txt", []byte(inputFile), 0644)

ReplaceCmd("config.json", "test.txt", "output.txt", "")
ReplaceCmd(ConfigurationMap, "test.txt", "output.txt", "")

file, _ := afero.ReadFile(AppFs, "output.txt")

Expand Down
9 changes: 8 additions & 1 deletion cli/cmd/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ var keyCmd = &cobra.Command{
outputFilePath := cmd.Flag("output").Value.String()
traceOutFilePath := cmd.Flag("memoryTraceOut").Value.String()

keyValue, err := actions.ReadKeyCmd(configFilePath, key, outputFilePath, traceOutFilePath)
configurationMap, err := actions.ReadConfigurationMap(configFilePath)

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

keyValue, err := actions.ReadKeyCmd(configurationMap, key, outputFilePath, traceOutFilePath)

if err != nil {
fmt.Println(err)
Expand Down
16 changes: 11 additions & 5 deletions cli/cmd/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
package cmd

import (
"fmt"

"github.com/mtintes/configamajig/actions"
"github.com/spf13/cobra"
)
Expand All @@ -14,14 +16,18 @@ var replaceCmd = &cobra.Command{
Short: "Replaces the variables in the input file using a config file",
Long: `This is for replacing the variables in the input file using a config file.`,
Run: func(cmd *cobra.Command, args []string) {
configMap := cmd.Flag("config").Value.String()

configMapPath := cmd.Flag("config").Value.String()
traceFileOutput := cmd.Flag("memoryTraceOut").Value.String()

inputPath := cmd.Flag("input").Value.String()

outputPath := cmd.Flag("output").Value.String()
actions.ReplaceCmd(configMap, inputPath, outputPath, traceFileOutput)

configurationMap, err := actions.ReadConfigurationMap(configMapPath)

if err != nil {
fmt.Println(err)
return
}
actions.ReplaceCmd(configurationMap, inputPath, outputPath, traceFileOutput)
},
}

Expand Down
56 changes: 0 additions & 56 deletions example-files/config.json

This file was deleted.

10 changes: 0 additions & 10 deletions example-files/dev.json

This file was deleted.

23 changes: 0 additions & 23 deletions example-files/global.json

This file was deleted.

9 changes: 0 additions & 9 deletions example-files/input1.txt

This file was deleted.

10 changes: 0 additions & 10 deletions example-files/integration.json

This file was deleted.

19 changes: 0 additions & 19 deletions example-files/local.json

This file was deleted.

10 changes: 0 additions & 10 deletions example-files/regional.json

This file was deleted.

Loading