Page:
DRY-RUN-PATTERN
Pages
AUTO-CREATE-ORG-PROJECTS
Branching-Strategy
CLI-AUTOMATION
Coding-Standards
DEPLOY-SCRIPTS
DOLIBARR-MODULE-IDS
DRY-RUN-PATTERN
Documentation-Standards
File-Header-Standards
JOOMLA-SYNC
LEGAL-DOC-GENERATOR-WEB-README
MONITORING-SCRIPTS
NEW-SCRIPTS
QUICKSTART-ORG-PROJECTS
RELEASE-MANAGEMENT
Version-Standard
WIKI-STANDARDS
WORKFLOW-STANDARDS
api-maintenance-index
api-plugin-index
api-tests-index
api-tests-sample-index
automation-README
automation-branch-version-automation
automation-repo-cleanup
client-repos
standards-mokostandards-file-spec
templates-client-waas
templates-dolibarr
templates-generic
templates-mcp
unnamed
workflows-README
workflows-auto-release
workflows-branch-protection
workflows-build-release
workflows-cascade-dev
workflows-changelog-management
workflows-demo-deployment
workflows-dev-branch-tracking
workflows-dev-deployment
workflows-index
workflows-release-system
workflows-renovate
workflows-reusable-workflows
workflows-rs-deployment
workflows-secret-scanning
workflows-shared-workflows
workflows-standards-compliance
workflows-static-analysis
workflows-sub-issue-management
workflows-update-server
workflows-workflow-architecture
Clone
3
DRY-RUN-PATTERN
Jonathan Miller edited this page 2026-06-21 05:40:01 +00:00
Standard Dry-Run Pattern
All mokocli scripts that perform write operations must implement the --dry-run flag using this standard pattern.
1. Add --dry-run Argument
parser.add_argument(
'--dry-run',
action='store_true',
help='Show what would be done without making changes'
)
2. Store and Announce
args = parser.parse_args()
dry_run = args.dry_run
if dry_run:
print("[DRY-RUN] Mode enabled - no changes will be made")
3. Guard Write Operations
if dry_run:
print(f"[DRY-RUN] Would create file: {filepath}")
else:
with open(filepath, 'w') as f:
f.write(content)
print(f"Created file: {filepath}")
4. Pattern for File Operations
def write_file(path, content, dry_run=False):
if dry_run:
print(f"[DRY-RUN] Would write to: {path}")
print(f"[DRY-RUN] Content length: {len(content)} bytes")
return
with open(path, 'w') as f:
f.write(content)
print(f"Wrote to: {path}")
5. Pattern for API Calls
def update_repository(repo, data, dry_run=False):
if dry_run:
print(f"[DRY-RUN] Would update repository: {repo}")
print(f"[DRY-RUN] Data: {data}")
return None
response = api.update(repo, data)
print(f"Updated repository: {repo}")
return response
6. Pattern for Shell Commands
import subprocess
def run_command(cmd, dry_run=False):
if dry_run:
print(f"[DRY-RUN] Would execute: {cmd}")
return 0
result = subprocess.run(cmd, shell=True)
return result.returncode
7. Summary Reporting
def main():
# ... script logic ...
if dry_run:
print()
print("=" * 60)
print("[DRY-RUN] Summary:")
print(f" Files that would be modified: {modified_count}")
print(f" Files that would be created: {created_count}")
print(f" API calls that would be made: {api_call_count}")
print("=" * 60)
else:
print()
print("Summary:")
print(f" Files modified: {modified_count}")
print(f" Files created: {created_count}")
print(f" API calls made: {api_call_count}")
Related
- ARCHITECTURE -- Platform scripts architecture
- WORKFLOW_STANDARDS -- CI/CD workflow conventions
Repo: mokocli · mokocli wiki
| Field | Value |
|---|---|
| Minimum Version | 04.07.00 |
| Platform | all |
| Applies To | All repositories |
| Revision | Date | Author | Description |
|---|---|---|---|
| 1.0 | 2026-05-09 | Moko Consulting | Initial version |
Pages
- AUTO-CREATE-ORG-PROJECTS
- Branching-Strategy
- CLI-AUTOMATION
- Coding-Standards
- DEPLOY-SCRIPTS
- DOLIBARR-MODULE-IDS
- DRY-RUN-PATTERN
- Documentation-Standards
- File-Header-Standards
- JOOMLA-SYNC
- LEGAL-DOC-GENERATOR-WEB-README
- MONITORING-SCRIPTS
- NEW-SCRIPTS
- QUICKSTART-ORG-PROJECTS
- RELEASE-MANAGEMENT
- Version-Standard
- WIKI-STANDARDS
- WORKFLOW-STANDARDS
- api-maintenance-index
- api-plugin-index
- api-tests-index
- api-tests-sample-index
- automation-README
- automation-branch-version-automation
- automation-repo-cleanup
- client-repos
- features
- operations
- reference
- standards-mokostandards-file-spec
- templates-client-waas
- templates-dolibarr
- templates-generic
- templates-mcp
- unnamed
- workflows-README
- workflows-auto-release
- workflows-branch-protection
- workflows-build-release
- workflows-cascade-dev
- workflows-changelog-management
- workflows-demo-deployment
- workflows-dev-branch-tracking
- workflows-dev-deployment
- workflows-index
- workflows-release-system
- workflows-renovate
- workflows-reusable-workflows
- workflows-rs-deployment
- workflows-secret-scanning
- workflows-shared-workflows
- workflows-standards-compliance
- workflows-static-analysis
- workflows-sub-issue-management
- workflows-update-server
- workflows-workflow-architecture
- workflows