-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
3,594 additions
and
179 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,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/conduktor/ctl/schema" | ||
"github.com/conduktor/ctl/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func initConsoleMkKind() { | ||
var prettyPrint *bool | ||
var nonStrict *bool | ||
|
||
var makeKind = &cobra.Command{ | ||
Use: "makeKind [file]", | ||
Short: "Make kind json from openapi file if file not given it will read from api", | ||
Long: ``, | ||
Aliases: []string{"mkKind", "makeConsoleKind"}, | ||
Args: cobra.RangeArgs(0, 1), | ||
Hidden: !utils.CdkDebug(), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runMkKind(cmd, args, *prettyPrint, *nonStrict, func() ([]byte, error) { return consoleApiClient().GetOpenApi() }, func(schema *schema.Schema, strict bool) (schema.KindCatalog, error) { | ||
return schema.GetConsoleKinds(strict) | ||
}) | ||
}, | ||
} | ||
rootCmd.AddCommand(makeKind) | ||
|
||
prettyPrint = makeKind.Flags().BoolP("pretty", "p", false, "Pretty print the output") | ||
nonStrict = makeKind.Flags().BoolP("non-strict", "n", false, "Don't be strict on the parsing of the schema") | ||
} |
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,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/conduktor/ctl/schema" | ||
"github.com/conduktor/ctl/utils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func initGatewayMkKind() { | ||
var prettyPrint *bool | ||
var nonStrict *bool | ||
|
||
var makeKind = &cobra.Command{ | ||
Use: "gatewayMakeKind [file]", | ||
Short: "Make kind json from openapi file if file not given it will read from api", | ||
Long: ``, | ||
Aliases: []string{"gatewayMkKind", "gwMkKind"}, | ||
Args: cobra.RangeArgs(0, 1), | ||
Hidden: !utils.CdkDebug(), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
runMkKind(cmd, args, *prettyPrint, *nonStrict, func() ([]byte, error) { return gatewayApiClient().GetOpenApi() }, func(schema *schema.Schema, strict bool) (schema.KindCatalog, error) { | ||
return schema.GetGatewayKinds(strict) | ||
}) | ||
}, | ||
} | ||
rootCmd.AddCommand(makeKind) | ||
|
||
prettyPrint = makeKind.Flags().BoolP("pretty", "p", false, "Pretty print the output") | ||
nonStrict = makeKind.Flags().BoolP("non-strict", "n", false, "Don't be strict on the parsing of the schema") | ||
} |
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,52 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/conduktor/ctl/schema" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func runMkKind(cmd *cobra.Command, args []string, prettyPrint bool, nonStrict bool, getOpenApi func() ([]byte, error), getKinds func(*schema.Schema, bool) (schema.KindCatalog, error)) { | ||
var kinds map[string]schema.Kind | ||
if len(args) == 1 { | ||
data, err := os.ReadFile(args[0]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
schema, err := schema.New(data) | ||
if err != nil { | ||
panic(err) | ||
} | ||
kinds, err = getKinds(schema, !nonStrict) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} else { | ||
data, err := getOpenApi() | ||
if err != nil { | ||
panic(err) | ||
} | ||
schema, err := schema.New(data) | ||
if err != nil { | ||
panic(err) | ||
} | ||
kinds, err = getKinds(schema, !nonStrict) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
var payload []byte | ||
var err error | ||
if prettyPrint { | ||
payload, err = json.MarshalIndent(kinds, "", " ") | ||
} else { | ||
payload, err = json.Marshal(kinds) | ||
} | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Print(string(payload)) | ||
} |
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
Oops, something went wrong.