#1055753 debci: --config option is broken

#1055753#5
Date:
2023-11-10 15:42:10 UTC
From:
To:
The --config option to the debci subcommands does not work:

$ mkdir /tmp/foo
$ echo 'debci_arch="i386"' > /tmp/foo/debci.conf

$ debci config --config /tmp/foo config_dir
config_dir=/tmp/foo

$ debci config --config /tmp/foo arch
arch=amd64

I believe that this is because it is processed too late.

It is first processed at the top lib/environment.sh, where it is used to read
the config, and set important variables, like debci_arch above.

Only after this has happened, its getopt(1) called. And I believe that all that
--config does at that point, is to update debci_config_dir.


In fact, I believe all of the option parsing should be moved to the very top,
as least some other options are also broken this way:

$ echo 'debci_arch_list="arm64 i386"' >> /tmp/foo/debci.conf
$ debci config --config /tmp/foo --arch=i386 arch
arch=i386
$ debci config --config /tmp/foo --arch=i386 arch_list
arch_list=amd64


I didn't want to file an MR outright, as I don't know the background behind the
current solution, and there might be a good reason for it.

Best,
Christian

#1055753#10
Date:
2023-11-10 17:10:05 UTC
From:
To:
Some shared options are defined in lib/environment.sh, I think that's
why it currently loads lib/environment.sh before processing the command
line options.

OTH your analysis is correct, as this causes the --config option to be
useless. A solution to this would be to break the common options into
their own file, include that in the scripts, call getopt, process
--config before anything else, then load lib/environment.sh for default
values, and only then process the rest of the options.

#1055753#15
Date:
2023-11-10 17:18:33 UTC
From:
To:
Hi Antonio,

unless I'm misreading something badly, both default values *and* option
processing are in lib/environment.sh -- it's just that getopt is called
somewhat after some defaults have been set, like config_dir, arch, etc.

My gut says moving getopt to the top of lib/environment.sh would fix
this, but its current position seemed like a deliberate choice, so I
assumed I was missing something.

Best,
Christian

#1055753#20
Date:
2023-11-14 11:35:50 UTC
From:
To:
The currenty situation is more a product of oversight than of design.
I'm wiling to review any solution you come up with.