Compare commits

...

3 Commits

4 changed files with 37 additions and 11 deletions

1
.gitignore vendored
View File

@ -14,6 +14,7 @@ vsg/version_info.*
# IDE files # IDE files
.idea/ .idea/
.vscode/ .vscode/
venv
# Ignore external repos used for tests # Ignore external repos used for tests
vsg/tests/external_repos/repos vsg/tests/external_repos/repos

View File

@ -132,7 +132,8 @@ def main():
fStatus, testCase, dJsonEntry, sOutputStd, sOutputErr, bKeepProcessingFiles = f((0, 'stdin')) fStatus, testCase, dJsonEntry, sOutputStd, sOutputErr, bKeepProcessingFiles = f((0, 'stdin'))
lReturn.append((fStatus, testCase, dJsonEntry)) lReturn.append((fStatus, testCase, dJsonEntry))
if sOutputStd: if sOutputStd:
print(sOutputStd) if not commandLineArguments.stdout:
print(sOutputStd)
if sOutputErr: if sOutputErr:
print(sOutputErr, file=sys.stderr) print(sOutputErr, file=sys.stderr)
@ -141,7 +142,8 @@ def main():
fStatus, testCase, dJsonEntry, sOutputStd, sOutputErr, bKeepProcessingFiles = f((iIndex + int(commandLineArguments.stdin), sFileName)) fStatus, testCase, dJsonEntry, sOutputStd, sOutputErr, bKeepProcessingFiles = f((iIndex + int(commandLineArguments.stdin), sFileName))
lReturn.append((fStatus, testCase, dJsonEntry)) lReturn.append((fStatus, testCase, dJsonEntry))
if sOutputStd: if sOutputStd:
print(sOutputStd) if not commandLineArguments.stdout:
print(sOutputStd)
if sOutputErr: if sOutputErr:
print(sOutputErr, file=sys.stderr) print(sOutputErr, file=sys.stderr)
if bKeepProcessingFiles: if bKeepProcessingFiles:
@ -154,7 +156,8 @@ def main():
fStatus, testCase, dJsonEntry, sOutputStd, sOutputErr, bKeepProcessingFiles = tResult fStatus, testCase, dJsonEntry, sOutputStd, sOutputErr, bKeepProcessingFiles = tResult
lReturn.append((fStatus, testCase, dJsonEntry)) lReturn.append((fStatus, testCase, dJsonEntry))
if sOutputStd: if sOutputStd:
print(sOutputStd) if not commandLineArguments.stdout:
print(sOutputStd)
if sOutputErr: if sOutputErr:
print(sOutputErr, file=sys.stderr) print(sOutputErr, file=sys.stderr)
if bKeepProcessingFiles: if bKeepProcessingFiles:
@ -181,7 +184,10 @@ def main():
if commandLineArguments.quality_report: if commandLineArguments.quality_report:
quality_report.write(commandLineArguments, dJson) quality_report.write(commandLineArguments, dJson)
sys.exit(fExitStatus) if commandLineArguments.no_failure:
sys.exit(0)
else:
sys.exit(fExitStatus)
def create_json_dictionary(): def create_json_dictionary():

View File

@ -122,10 +122,11 @@ def apply_rules(commandLineArguments, oConfig, tIndexFileName):
if commandLineArguments.fix: if commandLineArguments.fix:
if commandLineArguments.backup: if commandLineArguments.backup:
create_backup_file(sFileName) create_backup_file(sFileName)
oRules.fix( oRules.fix(commandLineArguments.fix_phase, commandLineArguments.skip_phase, fix_only)
commandLineArguments.fix_phase, commandLineArguments.skip_phase, fix_only if commandLineArguments.stdout:
) print("\n".join(oVhdlFile.get_lines()[1:]))
write_vhdl_file(oVhdlFile, oConfig.dConfig) else:
write_vhdl_file(oVhdlFile, oConfig.dConfig)
oRules.clear_violations() oRules.clear_violations()
oRules.check_rules( oRules.check_rules(

View File

@ -72,6 +72,12 @@ def parse_command_line_arguments():
parser.add_argument('--fix_only', action='store', help='Restrict fixing via JSON file.') parser.add_argument('--fix_only', action='store', help='Restrict fixing via JSON file.')
parser.add_argument('--stdin', action='store_true', default=False, parser.add_argument('--stdin', action='store_true', default=False,
help='Read VHDL input from stdin, disables all other file selections, disables multiprocessing') help='Read VHDL input from stdin, disables all other file selections, disables multiprocessing')
parser.add_argument(
"--stdout",
action="store_true",
default=False,
help="Write all file changes stdout instead of writing them in a file, enabling this will disable all diagnostics and just print a file fix",
)
parser.add_argument('--force_fix', action='store_true', default=False, parser.add_argument('--force_fix', action='store_true', default=False,
help='ALPHA: Apply fixes if syntax errors are detected.') help='ALPHA: Apply fixes if syntax errors are detected.')
@ -84,9 +90,9 @@ def parse_command_line_arguments():
type=__check_strict_positive, type=__check_strict_positive,
help="number of parallel jobs to use, default is the number of cpu cores", help="number of parallel jobs to use, default is the number of cpu cores",
) )
parser.add_argument('--debug', default=False, action='store_true', help='Displays verbose debug information') parser.add_argument("--debug", default=False, action="store_true", help="Displays verbose debug information")
parser.add_argument('filename_args', metavar='FILENAME', type=__is_valid_file, nargs='*', default=[], parser.add_argument("--no-failure", default=False, action="store_true", help="Always exits with exit code 0, usefull for scripting")
help='File to analyze') parser.add_argument("filename_args", metavar="FILENAME", type=__is_valid_file, nargs="*", default=[], help="File to analyze")
args_ = parser.parse_args() args_ = parser.parse_args()
@ -94,6 +100,7 @@ def parse_command_line_arguments():
validate_ap_argument(args_) validate_ap_argument(args_)
fix_filename_argument(args_) fix_filename_argument(args_)
fix_configuration_argument(args_) fix_configuration_argument(args_)
validate_stdout_argument(args_)
if sys.platform == "win32": if sys.platform == "win32":
# Work around https://bugs.python.org/issue26903 # Work around https://bugs.python.org/issue26903
@ -134,6 +141,17 @@ def validate_backup_argument(args_):
sys.exit(1) sys.exit(1)
def validate_stdout_argument(args_):
"""
The function validates the stdout option is only present when the fix option is also present.
"""
if args_.stdout and not args_.fix:
print("ERROR: --stdout argument requires --fix argument")
sys.exit(1)
if args_.stdout and not args_.stdin and len(args_.filename)>1:
print("ERROR: --stdout argument cannot be used with multiples files")
sys.exit(1)
def validate_ap_argument(args_): def validate_ap_argument(args_):
''' '''
The function validates the ap option is not present when the fix option is also present. The function validates the ap option is not present when the fix option is also present.