Skip to content

Commit bb2491b

Browse files
committed
feat: enhance help documentation with detailed usage examples
1 parent 91e2ceb commit bb2491b

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/dotcat/dotcat.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,50 @@ def red(text: str) -> str:
8282
<file> The input file (JSON, YAML, TOML, INI).
8383
<dotted-path> The dotted path to the desired data (e.g., project.authors).
8484
85+
{bold('EXAMPLES:')}
86+
dotcat config.json python.editor.tabSize
87+
dotcat pyproject.toml project.version
88+
dotcat package.json dependencies.react
89+
8590
See `dotcat --help` for more information.
8691
"""
8792

88-
HELP = f"""
93+
HELP_CORE = f"""
8994
{bold('dotcat')}
95+
9096
Read values, including nested values, from structured data files (JSON, YAML, TOML, INI)
9197
9298
{bold('USAGE:')}
93-
dotcat <file> <dotted-path>
99+
dotcat <file> <dotted-path>
94100
95-
{bold('EXAMPLES:')}
96-
dotcat config.json python.editor.tabSize
97-
dotcat somefile.toml a.b.c
98-
dotcat package.json dependencies.react
101+
{bold('EXAMPLES:')}"""
102+
103+
HELP_EXAMPLE = """
104+
# Access data by attribute path
105+
dotcat data.json person.name.first
106+
# John
107+
dotcat data.json person.name.last
108+
# Doe
109+
110+
# Controle your output format
111+
dotcat data.json person.name --output=yaml
112+
# name:
113+
# first: John
114+
# last: Doe
115+
dotcat data.json person.name --output=json
116+
# {"first": "John", "last": "Doe"}
117+
118+
# List access
119+
dotcat data.json person.friends@0
120+
# {"name":{"first": "Alice", "last": "Smith"}, "age": 25} -> item access
121+
dotcat data.json person.friends@2:4
122+
# [{"name":{"first": "Alice", "last": "Smith"}, "age": 25}, {"name":{"first": "Bob", "last": "Johnson"}, "age": 30}] -> slice access
123+
dotcat data.json person.friends@4:-1
124+
# ... from 5th to last item
99125
"""
100126

127+
HELP = HELP_CORE + HELP_EXAMPLE
128+
101129
######################################################################
102130
# Parsing functions
103131
######################################################################

0 commit comments

Comments
 (0)