Skip to content

Commit

Permalink
Fix package.yml stringify method
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Sep 18, 2023
1 parent 7e1f34a commit c65656f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/package-yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import * as YAML from "the/yaml"

export obj PackageYAML {
mut name: str
mut description: str
mut version: str
mut description: str
mut license: str
mut mainFile: str
mut files: str[]
mut packages: str[str]
Expand All @@ -21,12 +22,16 @@ export obj PackageYAML {
code += "name: " + self.name + os_EOL
}

if !self.version.empty {
code += "version: " + self.version + os_EOL
}

if !self.description.empty {
code += "description: " + self.description + os_EOL
}

if !self.version.empty {
code += "version: " + self.version + os_EOL
if !self.license.empty {
code += "license: " + self.license + os_EOL
}

if !self.mainFile.empty {
Expand Down Expand Up @@ -90,6 +95,15 @@ export fn PackageYAML_parse (content: str) PackageYAML {
throw error_NewError("Property `name` of package.yml expected to be a scalar")
}
}
} elif nodeKey == "version" {
if mappingNode.value != nil {
val := mappingNode.value
if val is YAML.NodeScalar {
result.version = YAML.Node_stringify(val)
} else {
throw error_NewError("Property `version` of package.yml expected to be a scalar")
}
}
} elif nodeKey == "description" {
if mappingNode.value != nil {
val := mappingNode.value
Expand All @@ -99,13 +113,13 @@ export fn PackageYAML_parse (content: str) PackageYAML {
throw error_NewError("Property `description` of package.yml expected to be a scalar")
}
}
} elif nodeKey == "version" {
} elif nodeKey == "license" {
if mappingNode.value != nil {
val := mappingNode.value
if val is YAML.NodeScalar {
result.version = YAML.Node_stringify(val)
result.license = YAML.Node_stringify(val)
} else {
throw error_NewError("Property `version` of package.yml expected to be a scalar")
throw error_NewError("Property `license` of package.yml expected to be a scalar")
}
}
} elif nodeKey == "main" {
Expand Down

0 comments on commit c65656f

Please sign in to comment.