MCPcopy Create free account
hub / github.com/aws-cloudformation/rain / formatString

Function formatString

internal/cmd/fmt/fmt.go:42–86  ·  view source on GitHub ↗
(input string, res *result)

Source from the content-addressed store, hash-verified

40}
41
42func formatString(input string, res *result) {
43
44 // Parse the template
45 source, err := parse.String(string(input))
46 if err != nil {
47 res.err = ui.Errorf(err, "unable to parse input")
48 return
49 }
50
51 config.Debugf("%s", node.ToSJson(source.Node))
52
53 if uncdk {
54 // Remove CDK Metadata
55 // Simplify logical IDs
56 err := format.UnCDK(source)
57 if err != nil {
58 res.err = ui.Errorf(err, "uncdk failed")
59 return
60 }
61 }
62
63 if dataModel {
64 res.output = node.ToJson(source.Node)
65 } else if pklFlag {
66 res.output, err = format.CftToPkl(source, pklBasic, pklPackageAlias)
67 if err != nil {
68 res.err = err
69 return
70 }
71 } else {
72 // Format the output
73 res.output = format.String(source, format.Options{
74 JSON: jsonFlag,
75 Unsorted: unsortedFlag,
76 })
77
78 // Verify the output is valid
79 if err = parse.Verify(source, res.output); err != nil {
80 res.err = err
81 return
82 }
83
84 res.ok = strings.TrimSpace(string(input)) == strings.TrimSpace(res.output)
85 }
86}
87
88func formatReader(name string, r io.Reader) result {
89 res := result{

Callers 2

formatReaderFunction · 0.85
formatFileFunction · 0.85

Calls 9

StringFunction · 0.92
ErrorfFunction · 0.92
DebugfFunction · 0.92
ToSJsonFunction · 0.92
UnCDKFunction · 0.92
ToJsonFunction · 0.92
CftToPklFunction · 0.92
StringFunction · 0.92
VerifyFunction · 0.92

Tested by

no test coverage detected