🔍 Code Extractor

function parse_arguments_v1

Maturity: 46

Parses command-line arguments for a legal contract extraction tool that processes documents from FileCloud storage.

File:
/tf/active/vicechatdev/contract_validity_analyzer/extractor.py
Lines:
694 - 744
Complexity:
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()

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function parse_arguments 93.0% similar

    Parses command-line arguments for a contract validity analysis tool that processes FileCloud documents with configurable options for paths, concurrency, output, and file filtering.

    From: /tf/active/vicechatdev/contract_validity_analyzer/main.py
  • function main 72.3% similar

    Main entry point function for a Legal Contract Data Extractor application that processes contracts from FileCloud, extracts data, and exports results to multiple formats (CSV, Excel, JSON).

    From: /tf/active/vicechatdev/contract_validity_analyzer/extractor.py
  • function main_v44 63.3% similar

    Entry point function for a FileCloud ACL management test script that parses command-line arguments and initiates ACL testing.

    From: /tf/active/vicechatdev/test_acl_functions.py
  • function main_v43 63.1% similar

    Entry point function that parses command-line arguments and orchestrates the FileCloud email processing workflow to find, download, and convert .msg files.

    From: /tf/active/vicechatdev/msg_to_eml.py
  • function main_v6 60.5% similar

    Main entry point function for the Contract Validity Analyzer application that orchestrates configuration loading, logging setup, FileCloud connection, and contract analysis execution.

    From: /tf/active/vicechatdev/contract_validity_analyzer/main.py
← Back to Browse