1717def do_shellcheck (
1818 melange_cfg : Mapping [str , Any ],
1919 shellcheck : list [str ],
20+ shellcheck_args : list [str ],
2021) -> None :
2122 if melange_cfg == {}:
2223 return
@@ -48,11 +49,14 @@ def do_shellcheck(
4849 ),
4950 ),
5051 )
52+ if len (all_steps ) == 0 :
53+ return
5154 for step , shfile in all_steps :
5255 shfile .write (step ["runs" ])
5356 shfile .close ()
5457 subprocess .check_call (
5558 ["/usr/bin/shellcheck" ]
59+ + shellcheck_args
5660 + ["--shell=busybox" , "--" ]
5761 + [os .path .basename (f .name ) for _ , f in all_steps ],
5862 cwd = os .getcwd (),
@@ -61,7 +65,12 @@ def do_shellcheck(
6165
6266def main (argv : Sequence [str ] | None = None ) -> int :
6367 parser = argparse .ArgumentParser ()
64- parser .add_argument ("filenames" , nargs = "*" , help = "Filenames to check." )
68+ parser .add_argument (
69+ "filenames" ,
70+ nargs = "*" ,
71+ help = "Filenames to check. You can also pass "
72+ "arguments to shellcheck before a '--' separator." ,
73+ )
6574 parser .add_argument (
6675 "--shellcheck" ,
6776 default = [
@@ -76,9 +85,16 @@ def main(argv: Sequence[str] | None = None) -> int:
7685 help = "shellcheck command" ,
7786 )
7887 args = parser .parse_args (argv )
88+ try :
89+ idx = args .filenames .index ("--" )
90+ shellcheck_args = args .filenames [:idx ]
91+ filenames = args .filenames [idx + 1 :]
92+ except ValueError :
93+ shellcheck_args = []
94+ filenames = args .filenames
7995
8096 melange_cfg = {}
81- for filename in args . filenames :
97+ for filename in filenames :
8298 with tempfile .NamedTemporaryFile (
8399 "w" ,
84100 delete_on_close = False ,
@@ -97,7 +113,11 @@ def main(argv: Sequence[str] | None = None) -> int:
97113 try :
98114 with open (compiled_out .name ) as compiled_in :
99115 melange_cfg = yaml .load (compiled_in )
100- do_shellcheck (melange_cfg , args .shellcheck )
116+ do_shellcheck (
117+ melange_cfg ,
118+ args .shellcheck ,
119+ shellcheck_args ,
120+ )
101121 except ruamel .yaml .YAMLError as exc :
102122 print (exc )
103123 return 1
0 commit comments