set default resource type to file when importing a resource
This commit is contained in:
parent
025f265705
commit
c25857fff9
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user