Quick Reference: Multi-Line Script Support¶
Quick Start¶
In console mode, you can now paste multiple commands:
> # Create and configure role in one go
> create-custom
> set-name --name MyRole
> set-description --description "My custom role"
> view
> save
Format¶
> # Comments start with #
> command-1 --option value
>
> # Blank lines are OK
> command-2 --flag
> command-3
Key Features¶
| Feature | Working | Example |
|---|---|---|
| Multi-line input | ✅ | Paste 5+ commands at once |
| Comment filtering | ✅ | # This is ignored |
| Blank lines | ✅ | Empty lines skipped automatically |
| Special characters | ✅ | "Multi word value", pipes, etc. |
| History support | ✅ | All commands recorded |
| Error handling | ✅ | One failure doesn't stop batch |
| Single-line mode | ✅ | Works unchanged |
Implementation¶
Files Modified¶
azure_custom_role_tool/cli.py- Added parsing & multi-line supporttests/test_multiline_console.py- 18 new tests (all passing)
Code Changes¶
# New function
def parse_multiline_commands(text: str) -> list[str]:
"""Filter comments/blanks from multi-line input"""
# Enhanced interactive_mode()
raw_input = prompt("> ..., multiline=True) # Accept multi-line
commands = parse_multiline_commands(raw_input) # Parse & filter
for command in commands:
# Execute each command
Test Results¶
✅ 126/126 tests passing - 108 existing tests (all still passing - no regressions) - 18 new tests for multi-line feature - 15 parsing tests (comments, blanks, edge cases) - 3 workflow tests (realistic scenarios)
Examples¶
Example 1: Simple Script¶
> create-custom
> set-name --name StorageRole
> view
Example 2: Script with Comments¶
> # Create custom role
> create-custom
>
> # Set properties
> set-name --name ComputeManager
> set-description --description "VM administration"
>
> # Save
> save
Example 3: Complex Workflow¶
> # Load existing role
> load --name BaseRole
>
> # Enhance with new permissions
> merge --role-dir /templates/enhancements
>
> # Update metadata
> set-name --name EnhancedRole
> set-description --description "Enhanced with new features"
>
> # Configure scopes
> set-scopes /subscriptions/prod-001,/subscriptions/prod-002
>
> # Deploy
> view --show-all
> save
> publish --subscription-id prod-001
How It Works¶
Input Rules¶
- Multi-line: Use Shift+Enter to continue, Enter to submit
- Comments: Lines starting with
#are ignored - Blanks: Empty lines are skipped
- Execution: Commands run sequentially, each with full error handling
Parsing¶
Raw Input:
"# Setup
create-custom
set-name --name Role
View"
↓ parse_multiline_commands()
Result:
["create-custom", "set-name --name Role", "View"]
Backward Compatibility¶
✅ 100% backwards compatible - Single-line input works exactly as before - No changes to command syntax - All existing features unchanged - No performance impact
Usage in CI/CD¶
Perfect for automation:
# Create a script file
cat > create_role.cli << 'EOF'
# Create and configure role
create-custom
set-name --name AutomationRole
set-description --description "Automated role setup"
set-scopes /subscriptions/prod-sub
save
publish --subscription-id prod-sub
EOF
# Execute (future enhancement - not yet implemented)
# azure-custom-role-tool console < create_role.cli
Troubleshooting¶
| Issue | Solution |
|---|---|
| Commands not executing | Check for syntax errors in earlier commands |
| Comments not ignored | Ensure # is at line start (after whitespace) |
| Copy-paste not working | Use Shift+Enter between lines, or try pasting one line at a time |
| Terminal issues | Some terminals may need special multi-line handling |
Documentation¶
Full Guides¶
- MULTILINE_SCRIPT_FEATURE.md - Complete feature documentation
- MULTILINE_SCRIPT_IMPLEMENTATION.md - Implementation details
Related Features¶
- UNIFIED_LOAD_FEATURE.md - Load from file/local/Azure with fallback
- ROLE_PROPERTIES_FEATURE.md - Set name, description, scopes
- FEATURE_REFERENCE.md - All commands reference
Performance¶
- ⚡ Fast parsing: O(n) time complexity
- 🎯 Minimal memory: No buffering overhead
- 📊 No slowdown: Single-line mode unchanged
- 🔄 Efficient execution: Sequential processing
Test Coverage¶
18 new tests cover:
Parsing Tests (15)
├── Single/multiple commands
├── Arguments & special characters
├── Comment filtering (5 tests)
├── Blank line handling (3 tests)
└── Edge cases (7 tests)
Workflow Tests (3)
├── Role creation workflow
├── Merge & modify workflow
└── Complex annotated workflow
Next Steps¶
Planned enhancements:
- Load scripts from files (load-script /path/to/script.cli)
- Conditional execution (if/then/else)
- Variable substitution
- Loop constructs
- Error recovery strategies
Status: ✅ Production Ready | Tests: 126/126 Passing