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

Removing .preprocessed.yml #83 #106

Merged
merged 3 commits into from
Apr 23, 2018
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@ perun
# Local perun configuration:
.perun

# This is a temporary file which is being created when FixFunctions is called from intrinsicsolver package.
.preprocessed.yml

# Internal Visual Studio Code config
.vscode
13 changes: 1 addition & 12 deletions intrinsicsolver/fixFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ var mapNature = functions[5:]

/*
FixFunctions : takes []byte file and firstly converts all single quotation marks to double ones (anything between single ones is treated as the rune in GoLang),
then deconstructs file into lines, checks for intrinsic functions. The FixFunctions has modes: `multiline`, `elongate`, `correctlong` and `temp`.
then deconstructs file into lines, checks for intrinsic functions. The FixFunctions has modes: `multiline`, `elongate` and `correctlong`.
Mode `multiline` looks for functions of a map nature where the function name is located in one line and it's body (map elements)
are located in the following lines (if this would be not fixed an error would be thrown: `json: unsupported type: map[interface {}]interface {}`).
The function changes the notation by putting function name in the next line with proper indentation.
Mode `elongate` exchanges the short function names into their proper, long equivalent.
Mode `correctlong` prepares the file for conversion into JSON. If the file is a YAML with every line being solicitously indented, there is no problem and the `elongate` mode is all we need.
But if there is any mixed notation (e.g. indented maps along with one-line maps, functions in one line with the key), parsing must be preceded with some additional operations.
Mode `temp` allows the user to save the result to a temporary file `.preprocessed.yml`.
The result is returned as a []byte array.
*/
func FixFunctions(template []byte, logger *logger.Logger, mode ...string) ([]byte, error) {
Expand Down Expand Up @@ -73,16 +72,6 @@ func FixFunctions(template []byte, logger *logger.Logger, mode ...string) ([]byt
stringStream := strings.Join(temporaryResult, "\n")
output := []byte(stringStream)

for _, m := range mode {
if m == "temp" {
if err := writeLines(temporaryResult, ".preprocessed.yml"); err != nil {
logger.Error(err.Error())
return nil, err
}
logger.Info("Created temporary file of a preprocessed template `.preprocessed.yml`")
}
}

return output, nil
}

Expand Down