44
55import argparse
66from dataclasses import fields
7+ from enum import Enum
78from pathlib import Path
89from sys import exit as sysexit
9- from sys import stdin , stdout
10+ from sys import stdout
1011
1112from configurator import Config
1213from configurator .node import ConfigNode
1920stdout .reconfigure (encoding = "utf-8" ) # type: ignore[general-type-issues]
2021
2122
23+ class ExitCode (Enum ):
24+ SUCCESS = 0
25+ UNVERIFIED_PACKAGE = 1
26+ NO_PACKAGES = 3
27+
28+
2229def cli () -> None : # pragma: no cover
2330 """Cli entry point."""
2431 parser = argparse .ArgumentParser (description = __doc__ , argument_default = argparse .SUPPRESS )
@@ -80,12 +87,8 @@ def cli() -> None: # pragma: no cover
8087 )
8188 args = vars (parser .parse_args ())
8289
83- stdin_path = Path ("__stdin__" )
8490 if not args .get ("requirements_paths" ):
85- if stdin .isatty ():
86- args ["requirements_paths" ] = ["pyproject.toml" ]
87- else :
88- stdin_path .write_text ("\n " .join (stdin .readlines ()), encoding = "utf-8" )
91+ args ["requirements_paths" ] = ["pyproject.toml" ]
8992
9093 config : ConfigNode = Config ()
9194
@@ -105,14 +108,13 @@ def cli() -> None: # pragma: no cover
105108 attestationcheckConf : LC_Config = LC_Config .model_validate ({** scopedData .data , ** args })
106109
107110 ec = main (attestationcheckConf )
108- stdin_path .unlink (missing_ok = True )
109111
110- sysexit (ec )
112+ sysexit (ec . value )
111113
112114
113- def main (attestationcheckConf : LC_Config ) -> int :
115+ def main (attestationcheckConf : LC_Config ) -> ExitCode :
114116 """Test entry point."""
115- exitCode = 0
117+ exitCode = ExitCode . SUCCESS
116118
117119 # File
118120 requirements_paths = attestationcheckConf .requirements_paths or {"__stdin__" }
@@ -148,23 +150,22 @@ def main(attestationcheckConf: LC_Config) -> int:
148150 )
149151 raise ValueError (msg )
150152
151- format_ = attestationcheckConf .format or "simple"
152- if attestationcheckConf .format in fmt .formatMap :
153- print (
154- fmt .fmt (
155- format_ ,
156- sorted (all_packages ),
157- hide_output_parameters ,
158- show_only_failing = attestationcheckConf .show_only_failing ,
159- ),
160- file = output_file ,
161- )
162- else :
163- exitCode = 2
153+ print (
154+ fmt .fmt (
155+ attestationcheckConf .format ,
156+ sorted (all_packages ),
157+ hide_output_parameters ,
158+ show_only_failing = attestationcheckConf .show_only_failing ,
159+ ),
160+ file = output_file ,
161+ )
164162
165163 # Exit code of 1 if args.zero
166- if attestationcheckConf .zero and incompatible :
167- exitCode = 1
164+ if attestationcheckConf .zero :
165+ if len (all_packages ) == 0 :
166+ exitCode = ExitCode .NO_PACKAGES
167+ if incompatible :
168+ exitCode = ExitCode .UNVERIFIED_PACKAGE
168169
169170 # Cleanup + exit
170171 if attestationcheckConf .file not in [None , "" ]:
0 commit comments