diff --git a/.stats.yml b/.stats.yml index d6c218a..6d30142 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1 @@ -configured_endpoints: 24 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openregister/openregister-4bd4cc957806a1fc7250db66762de302ee6718d21ebe7159b8753af53acc68df.yml -openapi_spec_hash: 2ada6c644f88094e8e542e539643f724 -config_hash: 42520b3d15dbe4a67577eb9c86e4ed01 +configured_endpoints: 26 diff --git a/go.mod b/go.mod index f223e7b..4100397 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/goccy/go-yaml v1.18.0 github.com/itchyny/json2yaml v0.1.4 github.com/muesli/reflow v0.3.0 - github.com/oregister/openregister-go/v2 v2.10.0 + github.com/oregister/openregister-go/v2 v2.12.0 github.com/stretchr/testify v1.10.0 github.com/tidwall/gjson v1.18.0 github.com/tidwall/pretty v1.2.1 diff --git a/go.sum b/go.sum index 517acf7..3722ef6 100644 --- a/go.sum +++ b/go.sum @@ -45,8 +45,8 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= -github.com/oregister/openregister-go/v2 v2.10.0 h1:SKV/Kco04Bd88vNo5jhO4WR2sw7swKsjokNV8ZspUZQ= -github.com/oregister/openregister-go/v2 v2.10.0/go.mod h1:CCIHIlKhI2GTYzCGjooEWb+Qmclab0n258lUEVuPKkA= +github.com/oregister/openregister-go/v2 v2.12.0 h1:UU3N0x2hPEMJjtLYwZlN2YpnGUu2O1acotxH8+ayBPo= +github.com/oregister/openregister-go/v2 v2.12.0/go.mod h1:CCIHIlKhI2GTYzCGjooEWb+Qmclab0n258lUEVuPKkA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= diff --git a/pkg/cmd/cmd.go b/pkg/cmd/cmd.go index 3002dd4..0c2de33 100644 --- a/pkg/cmd/cmd.go +++ b/pkg/cmd/cmd.go @@ -80,7 +80,6 @@ func init() { }, &requestflag.Flag[string]{ Name: "api-key", - Usage: "API Key Authentication\nProvide your API key as a Bearer token in the Authorization header.\n", Sources: cli.EnvVars("OPENREGISTER_API_KEY"), }, }, @@ -172,6 +171,15 @@ func init() { &insolvencyGetDetailsV1, }, }, + { + Name: "job", + Category: "API RESOURCE", + Suggest: true, + Commands: []*cli.Command{ + &jobCreateV1, + &jobGetV1, + }, + }, { Name: "@manpages", Usage: "Generate documentation for 'man'", diff --git a/pkg/cmd/job.go b/pkg/cmd/job.go new file mode 100644 index 0000000..efa6611 --- /dev/null +++ b/pkg/cmd/job.go @@ -0,0 +1,140 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "context" + "fmt" + + "github.com/oregister/openregister-cli/internal/apiquery" + "github.com/oregister/openregister-cli/internal/requestflag" + "github.com/oregister/openregister-go/v2" + "github.com/oregister/openregister-go/v2/option" + "github.com/tidwall/gjson" + "github.com/urfave/cli/v3" +) + +var jobCreateV1 = cli.Command{ + Name: "create-v1", + Usage: "Start a realtime request without waiting for it. The request returns at once\nwith a pending job. Use this instead of `realtime=true` when your client cannot\nkeep a request open for the minutes the Handelsregister may take.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "company-id", + Usage: "Unique company identifier.\nExample: DE-HRB-F1103-267645\n", + Required: true, + BodyPath: "company_id", + }, + &requestflag.Flag[string]{ + Name: "type", + Usage: `Allowed values: "company", "owners", "document".`, + Required: true, + BodyPath: "type", + }, + &requestflag.Flag[string]{ + Name: "document-category", + Usage: `Allowed values: "current_printout", "chronological_printout", "historical_printout", "structured_information", "shareholder_list", "articles_of_association".`, + BodyPath: "document_category", + }, + }, + Action: handleJobCreateV1, + HideHelpCommand: true, +} + +var jobGetV1 = cli.Command{ + Name: "get-v1", + Usage: "Get a job's status and, once it completed, its result in `results`. Polling is\nfree.", + Suggest: true, + Flags: []cli.Flag{ + &requestflag.Flag[string]{ + Name: "job-id", + Required: true, + PathParam: "job_id", + }, + }, + Action: handleJobGetV1, + HideHelpCommand: true, +} + +func handleJobCreateV1(ctx context.Context, cmd *cli.Command) error { + client := openregister.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + ApplicationJSON, + false, + ) + if err != nil { + return err + } + + params := openregister.JobNewV1Params{} + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Job.NewV1(ctx, params, options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "job create-v1", + Transform: transform, + }) +} + +func handleJobGetV1(ctx context.Context, cmd *cli.Command) error { + client := openregister.NewClient(getDefaultRequestOptions(cmd)...) + unusedArgs := cmd.Args().Slice() + if !cmd.IsSet("job-id") && len(unusedArgs) > 0 { + cmd.Set("job-id", unusedArgs[0]) + unusedArgs = unusedArgs[1:] + } + if len(unusedArgs) > 0 { + return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs) + } + + options, err := flagOptions( + cmd, + apiquery.NestedQueryFormatBrackets, + apiquery.ArrayQueryFormatComma, + EmptyBody, + false, + ) + if err != nil { + return err + } + + var res []byte + options = append(options, option.WithResponseBodyInto(&res)) + _, err = client.Job.GetV1(ctx, cmd.Value("job-id").(string), options...) + if err != nil { + return err + } + + obj := gjson.ParseBytes(res) + format := cmd.Root().String("format") + explicitFormat := cmd.Root().IsSet("format") + transform := cmd.Root().String("transform") + return ShowJSON(obj, ShowJSONOpts{ + ExplicitFormat: explicitFormat, + Format: format, + RawOutput: cmd.Root().Bool("raw-output"), + Title: "job get-v1", + Transform: transform, + }) +} diff --git a/pkg/cmd/job_test.go b/pkg/cmd/job_test.go new file mode 100644 index 0000000..d46b7f9 --- /dev/null +++ b/pkg/cmd/job_test.go @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +package cmd + +import ( + "testing" + + "github.com/oregister/openregister-cli/internal/mocktest" +) + +func TestJobCreateV1(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "job", "create-v1", + "--company-id", "company_id", + "--type", "company", + "--document-category", "current_printout", + ) + }) + + t.Run("piping data", func(t *testing.T) { + // Test piping YAML data over stdin + pipeData := []byte("" + + "company_id: company_id\n" + + "type: company\n" + + "document_category: current_printout\n") + mocktest.TestRunMockTestWithPipeAndFlags( + t, pipeData, + "--api-key", "string", + "job", "create-v1", + ) + }) +} + +func TestJobGetV1(t *testing.T) { + t.Skip("Mock server tests are disabled") + t.Run("regular flags", func(t *testing.T) { + mocktest.TestRunMockTestWithFlags( + t, + "--api-key", "string", + "job", "get-v1", + "--job-id", "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", + ) + }) +} diff --git a/scripts/build b/scripts/build index 3592cae..f30a9a9 100755 --- a/scripts/build +++ b/scripts/build @@ -5,7 +5,7 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go" echo "==> Building openregister" go build ./cmd/openregister diff --git a/scripts/link b/scripts/link index 9457d39..2e67e2f 100755 --- a/scripts/link +++ b/scripts/link @@ -5,7 +5,7 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go" REPLACEMENT="${1:-"../openregister-go"}" echo "==> Replacing Go SDK with $REPLACEMENT" diff --git a/scripts/lint b/scripts/lint index f01eabc..6b19907 100755 --- a/scripts/lint +++ b/scripts/lint @@ -5,7 +5,7 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go" echo "==> Running Go build" go build ./... diff --git a/scripts/run b/scripts/run index 559e9e8..8ed5a8a 100755 --- a/scripts/run +++ b/scripts/run @@ -5,6 +5,6 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go" go run ./cmd/openregister "$@" diff --git a/scripts/test b/scripts/test index 2075913..6dbbc1d 100755 --- a/scripts/test +++ b/scripts/test @@ -5,7 +5,7 @@ set -euo pipefail cd "$(dirname "$0")/.." # Mark the necessary Go modules as private to avoid Go's proxy -export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go/v2,github.com/stainless-sdks/openregister-go/v2" +export GOPRIVATE="${GOPRIVATE:+$GOPRIVATE,}github.com/oregister/openregister-go"