"""Authored command-line arrays, no process arguments/files/environment read."""
import argparse,contextlib,io,json,platform
def demo():
 bad=argparse.ArgumentParser(prog='authored',allow_abbrev=False);bad.add_argument('--enabled',type=bool)
 misleading=bad.parse_args(['--enabled','False']).enabled;assert misleading is True
 p=argparse.ArgumentParser(prog='authored',allow_abbrev=False);p.add_argument('--feature',action=argparse.BooleanOptionalAction,default=None)
 rows=[]
 for argv,want in [([],None),(['--feature'],True),(['--no-feature'],False)]:
  got=p.parse_args(argv).feature;assert got is want
  file_value=True;effective=file_value if got is None else got
  rows.append({'argv':argv,'cli':got,'effective':effective,'source':'file' if got is None else 'cli'})
 assert [x['effective'] for x in rows]==[True,True,False]
 precedence=[]
 for file_value in [None,True,False]:
  for cli in [None,True,False]:
   val=False;source='default'
   if file_value is not None:val=file_value;source='file'
   if cli is not None:val=cli;source='cli'
   precedence.append({'file':file_value,'cli':cli,'effective':val,'source':source})
 assert precedence[-1]['effective'] is False
 with contextlib.redirect_stderr(io.StringIO()):
  try:p.parse_args(['--unknown'])
  except SystemExit as e:code=e.code
  else:raise AssertionError('unknown accepted')
 assert code==2
 with contextlib.redirect_stderr(io.StringIO()):
  try:p.parse_args(['--feature','false'])
  except SystemExit as e:invalid_value_code=e.code
  else:raise AssertionError('unexpected value accepted')
 assert invalid_value_code==2
 return {'runtime':platform.python_version(),'bad_bool_False_string':misleading,'three_states':rows,'authored_default_file_cli_precedence':precedence,'unknown_option_exit':code,'unexpected_flag_value_exit':invalid_value_code,'scope':'Explicit precedence is this program policy, not argparse auto-reading config. No real argv/config/environment/secrets.'}
if __name__=='__main__':print(json.dumps(demo(),ensure_ascii=True,indent=2))
