Skip to content

Commit

Permalink
Implement Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
manabuishii committed Nov 30, 2017
1 parent 4a6763d commit 6e116f2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 2 deletions.
51 changes: 51 additions & 0 deletions field.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,54 @@ func (_ Field) New(i interface{}) Field {
}
return dest
}

// Inputs represents "inputs" field in CWL.
type Fields []Field

// New constructs new "Inputs" struct.
func (_ Fields) New(i interface{}) Fields {
dest := Fields{}
switch x := i.(type) {
case []interface{}:
for _, v := range x {
dest = append(dest, Field{}.New(v))
}
case map[string]interface{}:
//for key, v := range x {
for _, v := range x {
field := Field{}.New(v)
//field.Name = key
dest = append(dest, field)
}
}
return dest
}

// Len for sorting.
func (ins Fields) Len() int {
return len(ins)
}

// Less for sorting.
func (ins Fields) Less(i, j int) bool {
prev, next := ins[i].Binding, ins[j].Binding
switch [2]bool{prev == nil, next == nil} {
case [2]bool{true, true}:
return true
case [2]bool{false, true}:
return prev.Position < 0
case [2]bool{true, false}:
return next.Position > 0
default:
if prev.Position != next.Position {
return prev.Position <= next.Position
}
// sort by parameter name
return ins[i].Name <= ins[j].Name
}
}

// Swap for sorting.
func (ins Fields) Swap(i, j int) {
ins[i], ins[j] = ins[j], ins[i]
}
48 changes: 48 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cwl

import (
"fmt"
"sort"
"strings"
)

Expand All @@ -20,6 +21,7 @@ type Input struct {
Provided interface{} `json:"-"`
// Requirement ..
RequiredType *Type
Requirements Requirements
}

// New constructs "Input" struct from interface{}.
Expand Down Expand Up @@ -125,6 +127,52 @@ func (input Input) flattenWithRequiredType() []string {
// TODO: Join if .Separator is given
flattened = append(flattened, fmt.Sprintf("%s%v", field.Binding.Prefix, val))
}
} else {
switch v2 := val.(type) {
case []interface{}:
for _, val2 := range v2 {
switch v3 := val2.(type) {
case []interface{}:
case map[interface{}]interface{}:
for _, types := range input.Requirements[0].SchemaDefRequirement.Types {
val3array := []string{}
var val3count int = 0
sort.Sort(types.Fields)
for _, fields := range types.Fields {
for key3, val3 := range v3 {
if fields.Name == key3 {
for _, val3type := range fields.Types {
if val3type.Type == "" {
} else {
switch val3type.Type {
case "enum":
for _, symbol := range val3type.Symbols {
if symbol == val3 {
val3array = append(val3array, fmt.Sprintf("%v", val3))
val3count = val3count + 1
}
}
case "int":
if fields.Binding.Prefix != "" {
val3array = append(val3array, fields.Binding.Prefix, fmt.Sprintf("%v", val3))
val3count = val3count + 1
} else {
val3array = append(val3array, fmt.Sprintf("%v", val3))
val3count = val3count + 1
}
}
}
}
}
}
}
if len(v3) == val3count {
flattened = append(flattened, val3array...)
}
}
}
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Type struct {
Type string
Label string
Binding *Binding
Fields []Field // from CommandInputRecordSchema
Fields Fields // from CommandInputRecordSchema
Symbols []string // from CommandInputEnumSchema
Items []Type // from CommandInputArraySchema
Name string
Expand Down Expand Up @@ -48,7 +48,7 @@ func (_ Type) New(i interface{}) Type {
case "inputBinding":
dest.Binding = Binding{}.New(v)
case "fields":
dest.Fields = Field{}.NewList(v)
dest.Fields = Fields{}.New(v)
case "symbols":
dest.Symbols = StringArrayable(v)
case "name":
Expand Down

0 comments on commit 6e116f2

Please sign in to comment.