Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce log and refactor logic of cmd #18

Merged
merged 14 commits into from
Mar 8, 2024
Merged
22 changes: 22 additions & 0 deletions cmd/mksdk/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"context"
"log"
"os"

"github.com/paloaltonetworks/pan-os-codegen/pkg/commands/mksdk"
)

func main() {
var err error
ctx := context.Background()

cmd := mksdk.Command(ctx, os.Args[1:]...)
err = cmd.Setup()
if err == nil {
err = cmd.Execute()
} else {
log.Fatalf("There was an error when the execution: %s", err)
}
}
29 changes: 13 additions & 16 deletions cmd/mktp/main.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package main

import (
"context"
"fmt"
"os"
"context"
"log"
"os"

"github.com/paloaltonetworks/pan-os-codegen/pkg/mktp"
"github.com/paloaltonetworks/pan-os-codegen/pkg/commands/mktp"
)

func main() {
var err error
ctx := context.Background()
var err error
ctx := context.Background()

cmd := mktp.Command(ctx, os.Args[1:]...)
err = cmd.Setup()
if err == nil {
err = cmd.Execute()
}

if err != nil {
fmt.Fprintf(os.Stderr, err.Error() + "\n")
os.Exit(1)
}
cmd := mktp.Command(ctx, os.Args[1:]...)
err = cmd.Setup()
if err == nil {
err = cmd.Execute()
} else {
log.Fatalf("There was an error when the execution: %s", err)
}
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module github.com/paloaltonetworks/pan-os-codegen

require gopkg.in/yaml.v3 v3.0.1

go 1.21.4

require (
gopkg.in/yaml.v3 v3.0.1
)
58 changes: 58 additions & 0 deletions pkg/commands/mksdk/mksdk_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package mksdk

import (
"context"
"log"

"github.com/paloaltonetworks/pan-os-codegen/pkg/properties"
)

type Cmd struct {
ctx context.Context
args []string
configs []string
}

func Command(ctx context.Context, args ...string) *Cmd {
return &Cmd{
ctx: ctx,
args: args,
}
}

func (c *Cmd) Setup() error {
var err error

if c.configs == nil {
c.configs, err = properties.GetNormalizations()
}

return err
}

func (c *Cmd) Execute() error {
log.Print("Making Panos SDK - Pango\n")

for _, configPath := range c.configs {
log.Printf("Parsing %s...\n", configPath)
spec, err := properties.ParseSpec(configPath)
if err != nil {
log.Fatalf("error parsing %s - %s", configPath, err)
}

// Sanity check.
if err = spec.Sanity(); err != nil {
log.Fatalf("%s sanity failed: %s", configPath, err)
}

// Output normalization as pango code.
}

// Finalize pango code:
// * make fmt

// Done.
log.Printf("Done\n")

return nil
}
65 changes: 65 additions & 0 deletions pkg/commands/mktp/mktp_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package mktp

import (
"context"
"github.com/paloaltonetworks/pan-os-codegen/pkg/properties"
"log"
)

type Cmd struct {
ctx context.Context
args []string
configs []string
}

func Command(ctx context.Context, args ...string) *Cmd {
return &Cmd{
ctx: ctx,
args: args,
}
}

func (c *Cmd) Setup() error {
var err error

if c.configs == nil {
c.configs, err = properties.GetNormalizations()
}

return err
}

func (c *Cmd) Execute() error {
log.Print("Making panos Terraform provider\n")

//providerDataSources := make([]string, 0, 200)
//providerResources := make([]string, 0, 100)

for _, configPath := range c.configs {
log.Printf("Parsing %s...\n", configPath)
spec, err := properties.ParseSpec(configPath)
if err != nil {
log.Fatalf("error parsing %s - %s", configPath, err)
}

// Sanity check.
if err = spec.Sanity(); err != nil {
log.Fatalf("%s sanity failed: %s", configPath, err)
}

// Output as Terraform code.
}

// Finalize Terraform code.
// * output provider.go
// * write any static files
// * make fmt
// * output examples to ./examples
// * make docs
// * docs modifications (e.g. - subcategories)

// Done.
log.Printf("Done\n")

return nil
}
94 changes: 0 additions & 94 deletions pkg/mktp/cmd.go

This file was deleted.

Loading