maaslalani / invoice

Command line invoice generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configuration file not parsing correctly.

rouilj opened this issue · comments

Using a configuration file formatted like:

{
    "due": "net 30",
    "from": "XYzzY Inc.",
    "to": "ABCD Services",
    "tax": 0.06
}

and a command line:

./invoice generate --import ABCD.json --id "20230703-33" --title "Invoice for June 2023" --item "Addition of Autoresponder" --quantity 10  --rate 75 --discount .10 --item "Phone review of proposal" --quantity 1 --rate -75

I get:

2023/07/04 00:09:12 json file not correctly formatted

with no info as to why it failed. If I run jq . ABCD.json, it passes without error:

{
  "due": "net 30",
  "from": "XYzzY Inc.",
  "to": "ABCD Services",
  "tax": 0.06
}

Using your example input:

{
    "logo": "/path/to/image.png",
    "from": "Dream, Inc.",
    "to": "Imagine, Inc.",
    "tax": 0.13,
    "items": ["Yellow Rubber Duck", "Special Edition Plaid Rubber Duck"],
    "quantities": [5, 1],
    "rates": [25, 25],
}

fails jq because of the trailing ','. If I remove that so jq is happy, I still get the error: 'file is not formatted correctly'.

Ideas?

Thanks.

@rouilj I tested both cases and they work for me. I checked and the problem seems to be passing extra arguments with the import flag

@dvrd Hmm, for me even running:

./invoice generate --import ABCD.json

results in the same error. I would claim that --import should be able to work with command
line arguments in any case. I could see an ambiguity there though. If tax is set in ABCD.json and I use:

./invoice generate --import ABCD.json --tax 0.05

where "tax: 0.13" is present in ABCD.json, what is the tax? I can see two ways to handle it:

  1. command line overrides value in import so tax is 0.05.
  2. order of import and setting matter (last wins):
    • --import ABCD.json --tax 0.05 tax is 0.05
    • --tax 0.05 --import ABCD.json tax is 0.13
  3. I am not sure how to handle array values (e.g. quantity, item). Does use of --quantity and --item wipe out the setting in ---import file or do they get added to the array? I could see value for both cases.
    • the import file has a monthly retainer charge. Then items/quantity should be added to the import values.
    • the import file setting should be ignored and only command line item/quantity used

For testing, I am using docker to compile/run the example. On the host:

$ git clone https://github.com/maaslalani/invoice.git
$ cd invoice
$ docker run -u 1000:1000 -it -v $PWD:/mnt golang@sha256:344193a70dc3588452ea39b4a1e465a8d3c91f788ae053f7ee168cebf18e0a50

Note my uid/gid on the host is 1000, 1000.

Inside the running container:

$ go version
go version go1.20.5 linux/amd64
$ cd /mnt
$ mkdir /tmp/home
$ HOME=/tmp/home
$ go build -v
[bunch of stuff]
$ ./invoice generate --import ABCD.json --id "20230703-33" --title "Invoice for June 2023" --item "Addition of Autoresponder" --quantity 10  --rate 75 --discount .10 --item "Phone review of proposal" --quantity 1 --rate -75
2023/07/04 19:40:19 json file not correctly formatted
$ sum ABCD.json
25530     1 ABCD.json
$ cat ABCD.json
{
    "logo": "/path/to/image.png",
    "from": "Dream, Inc.",
    "to": "Imagine, Inc.",
    "tax": 0.13,
    "items": ["Yellow Rubber Duck", "Special Edition Plaid Rubber Duck"],
    "quantities": [5, 1],
    "rates": [25, 25],
}

Ideas on how to debug this?

Thanks.

Well for that output example you have an extra comma in the json. Json cannot have linggering commas

Well for that output example you have an extra comma in the json. Json cannot have linggering commas

Yup, that's how it's documented as I noted in my original report. jq noted that it was incorrect.
Removing the trailing ',' makes the bare ./invoice --import ABCD.json work correctly. Sorry for the bad test case. If the output had reported a line number where the error was or some info
about why it was incorrect it would help.

I agree that mixing --import and other command line parameters are the cause of the issue.

The example JSON contains a lingering comma.