function parse_arguments_v1
Parses command-line arguments for a legal contract extraction tool that processes documents from FileCloud storage.
/tf/active/vicechatdev/contract_validity_analyzer/extractor.py
694 - 744
simple
Purpose
This function sets up and parses command-line arguments for a contract data extraction application. It defines required and optional parameters including FileCloud path, processing limits, output file specifications, configuration file path, and logging verbosity. The function uses argparse to create a user-friendly CLI with help text and usage examples.
Source Code
def parse_arguments():
"""Parse command line arguments"""
parser = argparse.ArgumentParser(
description='Extract structured data from legal contracts in FileCloud',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python extractor.py --path "/contracts/legal" --limit 10
python extractor.py --path "/sanofi/agreements" --limit 5 --output contracts_output.csv
python extractor.py --path "/contracts" --config custom_config.yaml
"""
)
parser.add_argument(
'--path', '-p',
required=True,
help='FileCloud path to search for contracts (required)'
)
parser.add_argument(
'--limit', '-l',
type=int,
default=None,
help='Limit number of contracts to process (for testing)'
)
parser.add_argument(
'--output', '-o',
default=None,
help='Output filename (without extension) - will generate .csv, .xlsx, and .json files'
)
parser.add_argument(
'--output-json',
default=None,
help='Also save results as JSON file'
)
parser.add_argument(
'--config', '-c',
default=None,
help='Path to configuration file'
)
parser.add_argument(
'--verbose', '-v',
action='store_true',
help='Enable verbose logging'
)
return parser.parse_args()
Return Value
Returns an argparse.Namespace object containing parsed command-line arguments with the following attributes: 'path' (str, required FileCloud path), 'limit' (int or None, optional processing limit), 'output' (str or None, output filename without extension), 'output_json' (str or None, JSON output filename), 'config' (str or None, configuration file path), and 'verbose' (bool, verbose logging flag).
Dependencies
argparse
Required Imports
import argparse
Usage Example
import argparse
def parse_arguments():
parser = argparse.ArgumentParser(
description='Extract structured data from legal contracts in FileCloud',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
python extractor.py --path "/contracts/legal" --limit 10
python extractor.py --path "/sanofi/agreements" --limit 5 --output contracts_output.csv
python extractor.py --path "/contracts" --config custom_config.yaml
"""
)
parser.add_argument('--path', '-p', required=True, help='FileCloud path to search for contracts (required)')
parser.add_argument('--limit', '-l', type=int, default=None, help='Limit number of contracts to process (for testing)')
parser.add_argument('--output', '-o', default=None, help='Output filename (without extension) - will generate .csv, .xlsx, and .json files')
parser.add_argument('--output-json', default=None, help='Also save results as JSON file')
parser.add_argument('--config', '-c', default=None, help='Path to configuration file')
parser.add_argument('--verbose', '-v', action='store_true', help='Enable verbose logging')
return parser.parse_args()
# Usage in main script
if __name__ == '__main__':
args = parse_arguments()
print(f"Processing contracts from: {args.path}")
if args.limit:
print(f"Limiting to {args.limit} contracts")
if args.verbose:
print("Verbose logging enabled")
Best Practices
- Always call this function at the beginning of the main script execution to parse command-line arguments
- The --path argument is required; ensure users provide a valid FileCloud path
- Use --limit during testing to avoid processing large numbers of documents
- The --output argument generates multiple file formats (.csv, .xlsx, .json) automatically
- Enable --verbose flag for debugging and detailed logging during development
- The function includes helpful usage examples in the epilog that are displayed with --help
- Consider validating the parsed arguments after calling this function (e.g., checking if paths exist, validating limit is positive)
- The function uses sys.argv by default; for testing, you can pass custom arguments to parse_args()
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function parse_arguments 93.0% similar
-
function main 72.3% similar
-
function main_v44 63.3% similar
-
function main_v43 63.1% similar
-
function main_v6 60.5% similar