-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed incorrect handling of missing config with optional args (#80)
- Loading branch information
1 parent
45dac35
commit 55accbb
Showing
7 changed files
with
78 additions
and
25 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
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,49 @@ | ||
package definitions | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
"github.com/hashicorp/hcl/v2/hcldec" | ||
"github.com/hashicorp/hcl/v2/hclsyntax" | ||
"github.com/zclconf/go-cty/cty" | ||
|
||
"github.com/blackstork-io/fabric/parser/evaluation" | ||
"github.com/blackstork-io/fabric/pkg/diagnostics" | ||
) | ||
|
||
// Empty config, storing the range of the original block | ||
type ConfigEmpty struct { | ||
MissingItemRange hcl.Range | ||
} | ||
|
||
// Exists implements evaluation.Configuration. | ||
func (c *ConfigEmpty) Exists() bool { | ||
return false | ||
} | ||
|
||
// ParseConfig implements Configuration. | ||
func (c *ConfigEmpty) ParseConfig(spec hcldec.Spec) (val cty.Value, diags diagnostics.Diag) { | ||
emptyBody := &hclsyntax.Body{ | ||
SrcRange: c.MissingItemRange, | ||
EndRange: hcl.Range{ | ||
Filename: c.MissingItemRange.Filename, | ||
Start: c.MissingItemRange.End, | ||
End: c.MissingItemRange.End, | ||
}, | ||
} | ||
|
||
var diag hcl.Diagnostics | ||
val, diag = hcldec.Decode(emptyBody, spec, nil) | ||
for _, d := range diag { | ||
d.Summary = fmt.Sprintf("Missing required configuration: %s", d.Summary) | ||
} | ||
return val, diagnostics.Diag(diag) | ||
} | ||
|
||
// Range implements Configuration. | ||
func (c *ConfigEmpty) Range() hcl.Range { | ||
return c.MissingItemRange | ||
} | ||
|
||
var _ evaluation.Configuration = (*ConfigEmpty)(nil) |
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
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