Skip to content

Commit

Permalink
add test ; update TODO and license
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmanzo committed Feb 2, 2023
1 parent 4232846 commit a4b5750
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
7 changes: 4 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Todo

- [ ] add build feature that permits to run our image
- remember to use -p for any EXPOSEd port
- [ ] add examples and documentation
- [ ] define syntax validation rules and error reporting
- some examples: https://github.com/marquesmps/dockerfile_validator/blob/develop/src/rule_files/default_rules.yaml
Expand All @@ -11,7 +9,10 @@

## In progress

- [ ] publish package on nimble https://github.com/nim-lang/nimble#creating-packages
- [ ] add build feature that permits to run our image
- remember to use -p for any EXPOSEd port
- [x] publish package on nimble https://github.com/nim-lang/nimble#creating-packages
- PR done on https://github.com/nim-lang/packages, waiting for merge

## Done ✓

Expand Down
2 changes: 1 addition & 1 deletion containertools.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
version = "0.1.0"
author = "Andrea Manzini"
description = "A library to handle container file"
license = "GPL-2.0-only"
license = "GPL-3.0"
srcDir = "src"


Expand Down
11 changes: 11 additions & 0 deletions src/containertools/instruction.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ proc `$`*(self: Instruction): string =
proc unquote(s: string): seq[string] =
result = s.strip[1..^2].split(',').mapIt(it.strip[1..^2])

proc isNumeric(x: string): bool =
try:
discard parseInt(x)
result = true
except ValueError:
result = false


# parse a string into a Instruction
proc parse*(str: string): Instruction =
let tokens = str.strip().split(maxsplit = 1)
Expand All @@ -62,6 +70,9 @@ proc parse*(str: string): Instruction =
if (parsed_instr == CMD or parsed_instr == RUN or parsed_instr ==
ENTRYPOINT) and arg.startsWith('['):
return Instruction(cmd: parsed_instr, kind: Ak_array, array_val: unquote(arg))
if parsed_instr == EXPOSE and arg.isNumeric:
return Instruction(cmd: EXPOSE, kind: Ak_int, int_val: uint16(
arg.parseInt)) # TODO: can overflow
result = Instruction(cmd: parsed_instr, kind: Ak_string, str_val: arg)


Expand Down
5 changes: 4 additions & 1 deletion tests/test_parsing.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest2
import containertools


suite "parse single line":
test "can parse some instruction":
let testTable = [
Expand All @@ -13,7 +14,9 @@ suite "parse single line":
("COPY start.sh start.sh", Instruction(cmd: BuildInstruction.COPY,
kind: Ak_string, str_val: "start.sh start.sh")),
("RUN rm /usr/sbin/policy-rc.d", Instruction(cmd: BuildInstruction.RUN,
kind: Ak_string, str_val: "rm /usr/sbin/policy-rc.d"))
kind: Ak_string, str_val: "rm /usr/sbin/policy-rc.d")),
("EXPOSE 8080", Instruction(cmd: BuildInstruction.EXPOSE, kind: Ak_int,
int_val: 8080))
]
for items in testTable:
check: items[0].parse == items[1]
Expand Down

0 comments on commit a4b5750

Please sign in to comment.