Skip to content

Commit af66ee7

Browse files
committed
new commands
1 parent fe7f8ac commit af66ee7

File tree

6 files changed

+61
-56
lines changed

6 files changed

+61
-56
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
4+
## v 1.5
5+
6+
* Added DSL grammar for DSL [V2.13](https://docs.dimensions.ai/dsl/releasenotes.html#version-2-13-2025-november-week-of-10th)
7+
* Updated CLI special commands. Now starting with `/` instead of `.`
8+
39
## v 1.4
410

511
* Fix CLI [history bug](https://github.com/digital-science/dimcli/issues/80)

dimcli/VERSION.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# !/usr/bin/env python
22
# -*- coding: UTF-8 -*-
33

4-
__version__ = "1.4" # LATEST? => https://pypi.org/project/dimcli/
5-
__copyright__ = "CopyRight (C) 2018-2024 by Digital Science"
4+
__version__ = "1.5" # LATEST? => https://pypi.org/project/dimcli/
5+
__copyright__ = "CopyRight (C) 2018-2026 by Michele Pasin & Digital Science"
66
__license__ = "MIT"
77
__author__ = "Michele Pasin"
88
__author_email__ = "michele dot pasin at digital dash science dot com"

dimcli/core/dsl_grammar_extras.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010

1111
SYNTAX_DICT = {
1212
'allowed_starts_special_commands': {
13-
'help' : [],
14-
'.docs' : [],
15-
'quit' : [],
16-
'.show' : [],
17-
'.json_compact' : [],
18-
'.json_full' : [],
19-
'.export_as_html' : [],
20-
'.export_as_csv' : [],
21-
'.export_as_gist' : [],
22-
'.export_as_json' : [],
23-
'.export_as_bar_chart' : [],
24-
'.export_as_jupyter' : [],
25-
'.export_as_gsheets' : [],
26-
'.url' : [],
13+
'/help' : [],
14+
'/docs' : [],
15+
'/quit' : [],
16+
'/show' : [],
17+
'/json_compact' : [],
18+
'/json_full' : [],
19+
'/export_as_html' : [],
20+
'/export_as_csv' : [],
21+
'/export_as_gist' : [],
22+
'/export_as_json' : [],
23+
'/export_as_bar_chart' : [],
24+
'/export_as_jupyter' : [],
25+
'/export_as_gsheets' : [],
26+
'/url' : [],
2727
},
2828
'allowed_starts_dsl_query': {
2929
'search': [],

dimcli/repl/autocompletion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_completions(self, document, complete_event):
7272
entity = G.entity_type_for_source_facet(source, test_return_obj)
7373
candidates = G.fields_for_entity_from_source_facet(source, test_return_obj)
7474

75-
elif line_last_word(line_minus_current) in [".docs"]:
75+
elif line_last_word(line_minus_current) in ["/docs"]:
7676
candidates = G.sources() + G.entities()
7777

7878
elif line_last_word(line_minus_current) in ["describe"]:

dimcli/repl/repl.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,35 @@
4343

4444
HELP_MESSAGE = """COMMANDS LIST
4545
====================
46-
All special commands start with '.'
46+
All special commands start with '/'
4747
----
48-
>>> help: show this help message
48+
>>> /help: show this help message
4949
----
50-
>>> <tab>: autocomplete.
50+
>>> <tab>: autocomplete.
5151
----
52-
>>> .docs: print out documentation for DSL data objects.
53-
>>> .export_as_json: save results from last query as JSON file.
54-
>>> .export_as_csv: save results from last query as CSV file.
55-
>>> .export_as_gist: save results from last query as Github GIST.
56-
>>> .export_as_html: save results from last query as HTML file.
57-
>>> .export_as_bar_chart: save results from last query as Plotly bar chart.
58-
>>> .export_as_jupyter: save results from last query as Jupyter notebook.
59-
>>> .export_as_gsheets: save results from last query as Google Sheets (requires gspread credentials).
60-
>>> .show [optional: N]: print N results from last query, trying to build URLs for objects. Default N=10.
61-
>>> .json_compact: print results of last query as single-line JSON.
62-
>>> .json_full: print results of last query as formatted JSON.
63-
>>> .url: resolve a Dimensions ID into a public URL.
52+
>>> /docs: print out documentation for DSL data objects.
53+
>>> /export_as_json: save results from last query as JSON file.
54+
>>> /export_as_csv: save results from last query as CSV file.
55+
>>> /export_as_gist: save results from last query as Github GIST.
56+
>>> /export_as_html: save results from last query as HTML file.
57+
>>> /export_as_bar_chart: save results from last query as Plotly bar chart.
58+
>>> /export_as_jupyter: save results from last query as Jupyter notebook.
59+
>>> /export_as_gsheets: save results from last query as Google Sheets (requires gspread credentials).
60+
>>> /show [optional: N]: print N results from last query, trying to build URLs for objects. Default N=10.
61+
>>> /json_compact: print results of last query as single-line JSON.
62+
>>> /json_full: print results of last query as formatted JSON.
63+
>>> /url: resolve a Dimensions ID into a public URL.
6464
----
65-
>>> <Ctrl-o>: search docs online.
65+
>>> <Ctrl-o>: search docs online (type a search query first).
6666
>>> <Ctrl-c>: abort query.
6767
>>> <Ctrl-d>: exit console.
6868
----
69-
>>> quit: exit console
69+
>>> /quit: exit console
7070
====================
7171
*ABOUT AUTOCOMPLETE*
7272
Including a space between query elements (= keywords and operators) leads to better autocomplete results."""
7373

74-
WELCOME_MESSAGE = "Welcome! Type help for more info."
74+
WELCOME_MESSAGE = "Welcome! Type /help for more info."
7575
# WELCOME_MESSAGE = "Welcome! Type help for more info. Ready to query endpoint: %s"
7676

7777

@@ -105,16 +105,16 @@ def __init__(self, dslclient, databuffer):
105105

106106
def handle(self, text):
107107
"process text and delegate"
108-
if text.replace("\n", "").strip().startswith(".show") or text.replace("\n", "").strip().startswith(".json"):
108+
if text.replace("\n", "").strip().startswith("/show") or text.replace("\n", "").strip().startswith("/json"):
109109
self.show(text.replace("\n", "").strip())
110110

111-
elif text.replace("\n", "").strip().startswith(".export"):
111+
elif text.replace("\n", "").strip().startswith("/export"):
112112
self.export(text.replace("\n", "").strip())
113113

114-
elif text.replace("\n", "").strip().startswith(".docs"):
114+
elif text.replace("\n", "").strip().startswith("/docs"):
115115
self.docs_full(text.replace("\n", "").strip())
116116

117-
elif text.replace("\n", "").strip().startswith(".url"):
117+
elif text.replace("\n", "").strip().startswith("/url"):
118118
self.url_resolver(text.replace("\n", "").strip())
119119

120120
else:
@@ -125,7 +125,7 @@ def url_resolver(self, text):
125125
"""
126126
turn an ID into a Dimensions URL - print out results
127127
"""
128-
text = text.replace(".url", "").strip()
128+
text = text.replace("/url", "").strip()
129129
if len(text) > 0:
130130
print_dimensions_url(text)
131131

@@ -163,7 +163,7 @@ def docs_full(self, text):
163163
"""
164164
print out docs infos from 'describe' API
165165
"""
166-
text = text.replace(".docs", "").split()
166+
text = text.replace("/docs", "").split()
167167
if len(text) > 0:
168168
if text[0] in G.entities():
169169
res = self.dsl.query(f"describe entity {text[0]}")
@@ -221,25 +221,25 @@ def export(self, text):
221221
CONNECTION = get_global_connection()
222222
api_endpoint = CONNECTION.url
223223
# cases
224-
if text == ".export_as_html":
224+
if text == "/export_as_html":
225225
export_json_html(jsondata, query, api_endpoint, USER_EXPORTS_DIR)
226226

227-
elif text == ".export_as_gist":
227+
elif text == "/export_as_gist":
228228
export_gist(jsondata, query, api_endpoint)
229229

230-
elif text == ".export_as_csv":
230+
elif text == "/export_as_csv":
231231
export_json_csv(jsondata, query, USER_EXPORTS_DIR)
232232

233-
elif text == ".export_as_json":
233+
elif text == "/export_as_json":
234234
export_json_json(jsondata, query, USER_EXPORTS_DIR)
235235

236-
elif text == ".export_as_bar_chart":
236+
elif text == "/export_as_bar_chart":
237237
export_as_bar_chart(jsondata, query, USER_EXPORTS_DIR)
238238

239-
elif text == ".export_as_jupyter":
239+
elif text == "/export_as_jupyter":
240240
export_as_jupyter(jsondata, query, USER_EXPORTS_DIR)
241241

242-
elif text == ".export_as_gsheets":
242+
elif text == "/export_as_gsheets":
243243
export_as_gsheets_wrapper(jsondata, query)
244244

245245

@@ -259,14 +259,14 @@ def show(self, text):
259259
print("Nothing to show - please run a search first.")
260260
return
261261
# cases
262-
if text == ".json_compact":
262+
if text == "/json_compact":
263263
print_json_compact(jsondata)
264-
elif text == ".json_full":
264+
elif text == "/json_full":
265265
print_json_full(jsondata)
266266
else:
267-
# must be a simple ".show" + X command
267+
# must be a simple "/show" + X command
268268
try:
269-
no = text.replace(".show", "").strip()
269+
no = text.replace("/show", "").strip()
270270
slice_no = int(no)
271271
except ValueError:
272272
slice_no = DEFAULT_NO_RECORDS
@@ -333,9 +333,9 @@ def run(instance="live"):
333333
else:
334334
if text.strip() == "":
335335
continue
336-
elif text == "quit":
336+
elif text == "/quit":
337337
break
338-
elif text == "help":
338+
elif text == "/help":
339339
click.secho(HELP_MESSAGE, dim=True)
340340
continue
341341
# cm = CommandsManager(CLIENT,databuffer)

dimcli/utils/repl_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,7 @@ def preview_results(jsondata, maxitems=10):
667667
click.style(str(row)))
668668
if len(jsondata[key]) > maxitems:
669669
click.secho("---", dim=True)
670-
click.secho(f"Note: {maxitems} of {len(jsondata[key])} results shown. Use '.show <number>' to view more.", dim=True)
671-
670+
click.secho(f"Note: {maxitems} of {len(jsondata[key])} results shown. Use '/show <number>' to view more.", dim=True)
672671

673672

674673
def print_json_compact(jsondata):

0 commit comments

Comments
 (0)