Skip to content

Multi-Line Script Support Implementation Summary

Feature Completion Status: ✅ COMPLETE

The Azure Custom Role Designer CLI console mode now supports multi-line script input with automatic comment and blank line filtering.

What Was Implemented

1. Core Parsing Function

Location: cli.py

def parse_multiline_commands(text: str) -> list[str]:
    """Parse multi-line input, filtering out comments and empty lines."""
    commands = []
    for line in text.split('\n'):
        line = line.strip()
        if line and not line.startswith('#'):
            commands.append(line)
    return commands

Features: - Splits input by newlines - Strips whitespace from each line - Filters empty lines - Filters comment lines (starting with #) - Preserves hash characters in command arguments

2. Enhanced Interactive Mode

Location: cli.py

Key Changes: - prompt() now uses multiline=True parameter (Shift+Enter to continue, Enter to submit) - Input stored in raw_input instead of command - Calls parse_multiline_commands() to parse user input - Iterates through each parsed command sequentially - Displays each command with [dim] styling when multiple commands in batch - Proper error handling preserved for each command - Quit/exit triggers return instead of break to exit properly

Execution Flow:

User pastes multi-line script
prompt() captures all lines with multiline=True
parse_multiline_commands() filters comments/blanks
Iterate through each command
Display command (if batch mode)
Execute command with full error handling
Continue to next command

3. Comprehensive Test Suite

Location: tests/test_multiline_console.py

18 New Tests covering:

Core Parsing (15 tests)

  • Single command parsing
  • Multiple commands with newlines
  • Complex command arguments with quotes
  • Comment filtering (various scenarios)
  • Empty line handling
  • Whitespace-only line filtering
  • Comments with leading whitespace
  • Hash in middle of command (preserved)
  • Mixed scripts with comments, blanks, commands
  • Edge cases:
  • Only comments and blanks
  • Empty input
  • Whitespace-only input
  • Commands with pipes and special characters
  • Trailing newlines
  • Long descriptions

Realistic Workflows (3 tests)

  • Role creation workflow
  • Merge and modify workflow
  • Complex annotated workflow with detailed comments

All tests passing: ✅ 18/18

Test Verification

Before Implementation

  • 108 tests passing
  • All existing functionality working

After Implementation

  • 126 tests passing (108 existing + 18 new)
  • ✅ No regressions
  • ✅ All existing features work unchanged
  • ✅ New multi-line feature fully tested

Usage Examples

Simple Multi-Line Input

# Configure a custom role
create-custom
set-name --name DataRole
view

Script with Comments and Blanks

# Create and deploy role
create-custom

# Set metadata
set-name --name StorageManager
set-description --description "Storage administration"

# Configure scopes
set-scopes /subscriptions/prod-001

# Save and view
view
save

Output

[dim]>> create-custom[/dim]
✓ Created custom role

[dim]>> set-name --name StorageManager[/dim]
✓ Role name updated to 'StorageManager'

[dim]>> set-description --description "Storage administration"[/dim]
✓ Role description updated

[dim]>> set-scopes /subscriptions/prod-001[/dim]
✓ Assignable scopes updated

[dim]>> view[/dim]
(displays role details)

[dim]>> save[/dim]
✓ Role saved to local storage

Technical Implementation Details

Input Method

  • Uses prompt_toolkit's prompt() function
  • Parameter: multiline=True enables multi-line input
  • Shift+Enter: Add new line
  • Enter: Submit complete input

Command Parsing

  • O(n) time complexity where n = input characters
  • Efficient line-by-line processing
  • No buffering overhead
  • Minimal memory usage

Error Handling

  • Per-command error handling preserved
  • If one command fails, execution continues
  • Original exception types maintained
  • Error messages displayed clearly

Backward Compatibility

  • Single-line input works unchanged
  • No impact on existing commands
  • History recording unchanged
  • All existing features work 100%

Files Modified

  1. cli.py
  2. Added parse_multiline_commands() function (17 lines)
  3. Updated interactive_mode() to use multiline input (5 line changes)
  4. Added command iteration logic (40+ lines)
  5. Total: ~60 lines added/modified

  6. tests/test_multiline_console.py (NEW)

  7. 18 new comprehensive tests
  8. 200+ lines of test code
  9. All passing ✓

Feature Benefits

For Users

  • ✅ Copy-paste documentation examples directly
  • ✅ Execute batch operations in one input
  • ✅ Share reusable scripts with team
  • ✅ Include comments for clarity
  • ✅ Maintain clean, readable command sequences

For Development

  • ✅ Easier testing of workflows
  • ✅ Better documentation examples
  • ✅ Cleaner CI/CD automation
  • ✅ Reduced manual command entry

For Maintainability

  • ✅ Clear, focused implementation
  • ✅ Comprehensive test coverage
  • ✅ Well-documented code
  • ✅ No impact on existing functionality

Validation Checklist

  • ✅ Syntax validation (Python compilation successful)
  • ✅ Unit tests (126/126 passing)
  • ✅ Integration tests (all scenarios covered)
  • ✅ Edge cases (empty input, only comments, special characters)
  • ✅ Backward compatibility (all existing tests passing)
  • ✅ Error handling (exceptions properly caught)
  • ✅ Documentation (feature guide created)
  • ✅ Performance (efficient O(n) parsing)

Summary

The multi-line script support feature is production-ready with: - ✅ Complete implementation - ✅ Comprehensive testing (18 new tests, all passing) - ✅ Full backward compatibility - ✅ Clear documentation - ✅ No regressions (all 108 existing tests still passing) - ✅ Total test suite: 126 tests passing

Users can now paste multi-line command sequences with comments into console mode for batch automation, making the CLI more powerful and user-friendly.