set default resource type to file when importing a resource
All checks were successful
Lint / golangci-lint (push) Successful in 9m43s
Declarative Tests / test (push) Successful in 22s
Declarative Tests / build-fedora (push) Successful in 1m57s
Declarative Tests / build-ubuntu-focal (push) Successful in 4m13s

This commit is contained in:
Matthew Rich 2024-05-29 00:51:18 -07:00
parent 025f265705
commit c25857fff9
2 changed files with 13 additions and 8 deletions

View File

@ -11,10 +11,11 @@ import (
_ "errors" _ "errors"
"fmt" "fmt"
_ "gopkg.in/yaml.v3" _ "gopkg.in/yaml.v3"
"decl/internal/resource" "decl/internal/resource"
"decl/internal/source" "decl/internal/source"
"decl/internal/target" "decl/internal/target"
"decl/internal/codec" "decl/internal/codec"
"net/url"
) )
const ( const (
@ -138,7 +139,14 @@ func ImportSubCommand(cmd *flag.FlagSet, output io.Writer) (err error) {
if *ImportResource != "" { if *ImportResource != "" {
slog.Info("ImportResource", "resource", ImportResource) slog.Info("ImportResource", "resource", ImportResource)
if addResourceErr := d.AddResource(*ImportResource); addResourceErr != nil { resourceUri, uriErr := url.Parse(*ImportResource)
if uriErr != nil {
slog.Error("Failed adding resource", "error", uriErr)
}
if resourceUri.Scheme == "" {
resourceUri.Scheme = "file"
}
if addResourceErr := d.AddResource(resourceUri.String()); addResourceErr != nil {
slog.Error("Failed adding resource", "error", addResourceErr) slog.Error("Failed adding resource", "error", addResourceErr)
} }
} }

View File

@ -125,15 +125,12 @@ func (d *Document) AddResourceDeclaration(resourceType string, resourceDeclarati
} }
func (d *Document) AddResource(uri string) error { func (d *Document) AddResource(uri string) error {
//parsedResourceURI, e := url.Parse(uri)
//if e == nil {
decl := NewDeclaration() decl := NewDeclaration()
if e := decl.SetURI(uri); e != nil { if e := decl.SetURI(uri); e != nil {
return e return e
} }
d.ResourceDecls = append(d.ResourceDecls, *decl) d.ResourceDecls = append(d.ResourceDecls, *decl)
//}
return nil return nil
} }