asottile / dockerfile

Parse a dockerfile into a high-level representation using the official go parser
MIT License
95 stars 18 forks source link

I the latest version, The `cmd` field of Command is now uppercase after parsing #101

Closed ioah86 closed 2 years ago

ioah86 commented 2 years ago

I can't see anywhere if that was an intentional change, but using version 3.2.0 in Python 3.10.1 on Linux (5.15.14-1-lts #1 SMP Tue, 11 Jan 2022 15:37:45 +0000 x86_64 GNU/Linux) causes parsing of files to have the Command.cmd field to be uppercase.

Here is the parse result in the new version

In [1]: import dockerfile

In [3]: conf = dockerfile.parse_file('Dockerfile')

In [4]: conf
Out[4]: 
(Command(cmd='FROM', sub_cmd=None, json=False, original='FROM ubuntu:16.04', start_line=1, end_line=1, flags=(), value=('ubuntu:16.04',)),
 Command(cmd='WORKDIR', sub_cmd=None, json=False, original='WORKDIR foo/bar', start_line=3, end_line=3, flags=(), value=('foo/bar',)),
 Command(cmd='ADD', sub_cmd=None, json=False, original='ADD foo foo', start_line=4, end_line=4, flags=(), value=('foo', 'foo')))

Where Dockerfile is the following:

FROM ubuntu:16.04

WORKDIR foo/bar
ADD foo foo

In the previous versions, it was always lowercase, and since you also display the commands in dockerfile.all_cmds() as lowercase, I think it is not on purpose.

asottile commented 2 years ago

docker itself changed how these were parsed -- the difference happened when we updated here: #83