Skip to content

Commit

Permalink
adress review for local path
Browse files Browse the repository at this point in the history
  • Loading branch information
guineveresaenger committed Dec 3, 2024
1 parent be23f0a commit 7095de4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions dynamic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func initialSetup() (info.Provider, pfbridge.ProviderMetadata, func() error) {
}

if args.Local != nil {
if args.Local.DocsLocation != "" {
info.UpstreamRepoPath = args.Local.DocsLocation
if args.Local.UpstreamRepoPath != "" {
info.UpstreamRepoPath = args.Local.UpstreamRepoPath
fullDocs = true
}
}
Expand Down
18 changes: 12 additions & 6 deletions dynamic/parameterize/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ type RemoteArgs struct {
Name string
// Version is the (possibly empty) version constraint on the provider.
Version string
// Docs is the (possibly empty) argument to download and write docs into the schema
// Docs indicates if full schema documentation should be generated.
Docs bool
}

// LocalArgs represents a local TF provider referenced by path.
type LocalArgs struct {
// Path is the path to the provider binary. It can be relative or absolute.
Path string
// DocsLocation is the path to the provider documentation.
DocsLocation string
// UpstreamRepoPath (if provided) is the local path to the dynamically bridged Terraform provider's repo.
//
// If set, full documentation will be generated for the provider.
// If not set, only documentation from the TF provider's schema will be used.
UpstreamRepoPath string
}

func ParseArgs(args []string) (Args, error) {
Expand All @@ -49,11 +52,14 @@ func ParseArgs(args []string) (Args, error) {
(strings.HasPrefix(args[0], "./") || strings.HasPrefix(args[0], "/")) {
if len(args) > 1 {
docsArg := args[1]
docsLocation, found := strings.CutPrefix(docsArg, "docsLocation=")
upstreamRepoPath, found := strings.CutPrefix(docsArg, "upstreamRepoPath=")
if !found {
return Args{}, fmt.Errorf("path based providers are only parameterized by 2 arguments: <path> [docsLocation]")
return Args{}, fmt.Errorf("path based providers are only parameterized by 2 arguments: <path> [upstreamRepoPath]")
}
return Args{Local: &LocalArgs{Path: args[0], DocsLocation: docsLocation}}, nil
if upstreamRepoPath == "" {
return Args{}, fmt.Errorf("upstreamRepoPath must be set to a non-empty value: upstreamRepoPath=path/to/files")
}
return Args{Local: &LocalArgs{Path: args[0], UpstreamRepoPath: upstreamRepoPath}}, nil
}
return Args{Local: &LocalArgs{Path: args[0]}}, nil
}
Expand Down
15 changes: 11 additions & 4 deletions dynamic/parameterize/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,26 @@ func TestParseArgs(t *testing.T) {
name: "local too many args",
args: []string{"./my-provider", "nonsense"},
errMsg: autogold.Expect(
"path based providers are only parameterized by 2 arguments: <path> [docsLocation]",
"path based providers are only parameterized by 2 arguments: <path> [upstreamRepoPath]",
),
},
{
name: "local with docs location",
args: []string{"./my-provider", "docsLocation=./my-provider"},
args: []string{"./my-provider", "upstreamRepoPath=./my-provider"},
expect: Args{
Local: &LocalArgs{
Path: "./my-provider",
DocsLocation: "./my-provider",
Path: "./my-provider",
UpstreamRepoPath: "./my-provider",
},
},
},
{
name: "local empty upstreamRepoPath",
args: []string{"./my-provider", "upstreamRepoPath="},
errMsg: autogold.Expect(
"upstreamRepoPath must be set to a non-empty value: upstreamRepoPath=path/to/files",
),
},
{
name: "remote",
args: []string{"my-registry.io/typ"},
Expand Down

0 comments on commit 7095de4

Please sign in to comment.