-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc_utils_cli.py
More file actions
158 lines (134 loc) · 4.99 KB
/
doc_utils_cli.py
File metadata and controls
158 lines (134 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python3
"""
doc-utils - CLI tools for AsciiDoc documentation projects
Main entry point that provides a hub for all doc-utils tools.
"""
import argparse
import sys
from doc_utils.version import __version__
from doc_utils.version_check import check_version_on_startup
# Tool definitions with descriptions
TOOLS = [
{
'name': 'validate-links',
'description': 'Validates all links in documentation with URL transposition',
'example': 'validate-links --transpose "https://prod--https://preview"'
},
{
'name': 'extract-link-attributes',
'description': 'Extracts link/xref macros with attributes into reusable definitions',
'example': 'extract-link-attributes --dry-run'
},
{
'name': 'replace-link-attributes',
'description': 'Resolves Vale LinkAttribute issues by replacing attributes in link URLs',
'example': 'replace-link-attributes --dry-run'
},
{
'name': 'format-asciidoc-spacing',
'description': 'Standardizes spacing after headings and around includes',
'example': 'format-asciidoc-spacing --dry-run modules/'
},
{
'name': 'check-scannability',
'description': 'Analyzes document readability by checking sentence/paragraph length',
'example': 'check-scannability --max-sentence-length 5'
},
{
'name': 'archive-unused-files',
'description': 'Finds and optionally archives unreferenced AsciiDoc files',
'example': 'archive-unused-files # preview\narchive-unused-files --archive # execute'
},
{
'name': 'archive-unused-images',
'description': 'Finds and optionally archives unreferenced image files',
'example': 'archive-unused-images # preview\narchive-unused-images --archive # execute'
},
{
'name': 'find-unused-attributes',
'description': 'Identifies unused attribute definitions in AsciiDoc files',
'example': 'find-unused-attributes # auto-discovers attributes files'
},
{
'name': 'convert-callouts-to-deflist',
'description': 'Converts callouts to definition lists (batch mode)',
'example': 'convert-callouts-to-deflist --dry-run modules/'
},
{
'name': 'convert-callouts-interactive',
'description': 'Interactively converts callouts with per-block format selection',
'example': 'convert-callouts-interactive modules/'
},
]
def print_tools_list():
"""Print a formatted list of all available tools."""
print("\n🛠️ Available Tools:\n")
for tool in TOOLS:
# Print tool name and description
experimental = " [EXPERIMENTAL]" if "[EXPERIMENTAL]" in tool['description'] else ""
desc = tool['description'].replace(" [EXPERIMENTAL]", "")
print(f" {tool['name']}{experimental}")
print(f" {desc}")
print()
def print_help():
"""Print comprehensive help information."""
print(f"doc-utils v{__version__}")
print("\nCLI tools for maintaining clean, consistent AsciiDoc documentation repositories.")
print_tools_list()
print("📚 Usage:")
print(" doc-utils --version Show version information")
print(" doc-utils --list List all available tools")
print(" doc-utils --help Show this help message")
print(" <tool-name> --help Show help for a specific tool")
print()
print("📖 Documentation:")
print(" https://rolfedh.github.io/doc-utils/")
print()
print("💡 Examples:")
print(" find-unused-attributes")
print(" check-scannability --max-sentence-length 5")
print(" format-asciidoc-spacing --dry-run modules/")
print()
print("⚠️ Safety First:")
print(" Always work in a git branch and review changes with 'git diff'")
print()
def main():
"""Main entry point for doc-utils command."""
# Check for updates (non-blocking)
check_version_on_startup()
parser = argparse.ArgumentParser(
description='doc-utils - CLI tools for AsciiDoc documentation projects',
add_help=False # We'll handle help ourselves
)
parser.add_argument(
'--version',
action='version',
version=f'doc-utils {__version__}'
)
parser.add_argument(
'--list',
action='store_true',
help='List all available tools'
)
parser.add_argument(
'--help', '-h',
action='store_true',
help='Show this help message'
)
# Parse known args to allow for future expansion
args, remaining = parser.parse_known_args()
# Handle flags
if args.list:
print_tools_list()
return 0
if args.help or len(sys.argv) == 1:
print_help()
return 0
# If we get here with remaining args, show help
if remaining:
print(f"doc-utils: unknown command or option: {' '.join(remaining)}")
print("\nRun 'doc-utils --help' for usage information.")
return 1
return 0
if __name__ == '__main__':
sys.exit(main())