Skip to content

Commit

Permalink
use log "github.com/sirupsen/logrus"
Browse files Browse the repository at this point in the history
  • Loading branch information
widmogrod committed Oct 8, 2023
1 parent 31f4fcc commit 4e03e41
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 5 deletions.
8 changes: 5 additions & 3 deletions cmd/mkunion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package main

import (
"context"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/widmogrod/mkunion"
"github.com/widmogrod/mkunion/x/shape"
"log"
"os"
"os/signal"
"path"
Expand All @@ -17,6 +16,10 @@ import (
func main() {
ctx, _ := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)

// set log level to error
log.SetOutput(os.Stderr)
log.SetLevel(log.ErrorLevel)

var app *cli.App
app = &cli.App{
Name: mkunion.Program,
Expand Down Expand Up @@ -219,7 +222,6 @@ func main() {
}

for _, structLike := range inferred.RetrieveStruct() {
fmt.Println(shape.ToStr(structLike))
tsr.AddStruct(structLike)
}

Expand Down
3 changes: 3 additions & 0 deletions example/react-app/generated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package react_app

//go:generate go run ../../cmd/mkunion/main.go shape-export --output=./src/workflow --input-go-file=../../x/workflow/workflow_machine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Schema = any
1 change: 1 addition & 0 deletions example/react-app/src/workflow/time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Duration = number
174 changes: 174 additions & 0 deletions example/react-app/src/workflow/workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
//generated by mkunion
export type Predicate = {
"workflow.And": And
} | {
"workflow.Or": Or
} | {
"workflow.Not": Not
} | {
"workflow.Compare": Compare
}

export type And = {
L?: Predicate[],
}

export type Or = {
L?: Predicate[],
}

export type Not = {
P?: Predicate,
}

export type Compare = {
Operation?: string,
Left?: Reshaper,
Right?: Reshaper,
}

//generated by mkunion
export type Command = {
"workflow.Run": Run
} | {
"workflow.Callback": Callback
}

export type Run = {
Flow?: Worflow,
Input?: schema.Schema,
}

export type Callback = {
CallbackID?: string,
Result?: schema.Schema,
}

//generated by mkunion
export type State = {
"workflow.NextOperation": NextOperation
} | {
"workflow.Done": Done
} | {
"workflow.Error": Error
} | {
"workflow.Await": Await
}

export type NextOperation = {
Result?: schema.Schema,
BaseState?: BaseState,
}

export type Done = {
Result?: schema.Schema,
BaseState?: BaseState,
}

export type Error = {
Code?: string,
Reason?: string,
Retried?: number,
MaxRetries?: number,
BaseState?: BaseState,
}

export type Await = {
CallbackID?: string,
Timeout?: time.Duration,
BaseState?: BaseState,
}

//generated by mkunion
export type Worflow = {
"workflow.Flow": Flow
} | {
"workflow.FlowRef": FlowRef
}

export type Flow = {
Name?: string,
Arg?: string,
Body?: Expr[],
}

export type FlowRef = {
FlowID?: string,
}

//generated by mkunion
export type Expr = {
"workflow.End": End
} | {
"workflow.Assign": Assign
} | {
"workflow.Apply": Apply
} | {
"workflow.Choose": Choose
}

export type End = {
ID?: string,
Result?: Reshaper,
}

export type Assign = {
ID?: string,
VarOk?: string,
VarErr?: string,
Val?: Expr,
}

export type Apply = {
ID?: string,
Name?: string,
Args?: Reshaper[],
Await?: ApplyAwaitOptions,
}

export type Choose = {
ID?: string,
If?: Predicate,
Then?: Expr[],
Else?: Expr[],
}

//generated by mkunion
export type Reshaper = {
"workflow.GetValue": GetValue
} | {
"workflow.SetValue": SetValue
}

export type GetValue = {
Path?: string,
}

export type SetValue = {
Value?: schema.Schema,
}

export type Execution = {
FlowID?: string,
Status?: State,
Location?: string,
StartTime?: number,
EndTime?: number,
Variables?: {[key: string]: any},
}
export type BaseState = {
Flow?: Worflow,
RunID?: string,
StepID?: string,
Variables?: {[key: string]: any},
ExprResult?: {[key: string]: any},
}
export type ApplyAwaitOptions = {
Timeout?: time.Duration,
}
export type ResumeOptions = {
Timeout?: time.Duration,
}

import * as schema from './github_com_widmogrod_mkunion_x_schema'
import * as time from './time'
4 changes: 2 additions & 2 deletions infer_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func (f *InferredInfo) Visit(n ast.Node) ast.Visitor {
})
break
default:
log.Errorf("infer_defaults: unknown ast type embedded in struct: %T\n", typ)
log.Warnf("infer_defaults: unknown ast type embedded in struct: %T\n", typ)
continue
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ func (f *InferredInfo) Visit(n ast.Node) ast.Visitor {
typ = shape.FromAst(ttt, shape.InjectPkgName(f.PkgImportName, f.PackageName))

default:
log.Errorf("infer_defaults: unknown ast type in %s.%s: %T\n", f.currentType, fieldName.Name, ttt)
log.Warnf("infer_defaults: unknown ast type in %s.%s: %T\n", f.currentType, fieldName.Name, ttt)
typ = &shape.Any{}
}

Expand Down

0 comments on commit 4e03e41

Please sign in to comment.