Skip to content

Commit f8b783e

Browse files
reckless: add list command to list reckless managed plugins
'Reckless list' will now list all plugins installed and managed by reckless. Changelog-Added: reckless: list command lists plugins installed by reckless.
1 parent 5250431 commit f8b783e

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

tools/reckless

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,60 @@ def update_plugins(plugin_name: str):
19121912
return update_results
19131913

19141914

1915+
def extract_metadata(plugin_name: str) -> dict:
1916+
metadata_file = Path(RECKLESS_CONFIG.reckless_dir) / plugin_name / '.metadata'
1917+
if not metadata_file.exists():
1918+
return None
1919+
1920+
with open(metadata_file, 'r') as md:
1921+
lines = md.readlines()
1922+
metadata_headers = ['installation date',
1923+
'installation time',
1924+
'original source',
1925+
'requested commit',
1926+
'installed commit'
1927+
]
1928+
metadata = {}
1929+
current_key = None
1930+
1931+
for line in lines:
1932+
if line.strip() in metadata_headers:
1933+
current_key = line.strip()
1934+
continue
1935+
1936+
if current_key:
1937+
metadata.update({current_key: line.strip()})
1938+
current_key = None
1939+
1940+
return metadata
1941+
1942+
1943+
def listinstalled():
1944+
"""list all plugins currently managed by reckless"""
1945+
dir_contents = os.listdir(RECKLESS_CONFIG.reckless_dir)
1946+
plugins = {}
1947+
for plugin in dir_contents:
1948+
if (Path(RECKLESS_CONFIG.reckless_dir) / plugin).is_dir():
1949+
# skip hidden dirs such as reckless' .remote_sources
1950+
if plugin[0] == '.':
1951+
continue
1952+
plugins.update({plugin: None})
1953+
longest = {'name': 0,
1954+
'inst': 0}
1955+
# Format output in a simple table
1956+
name_len = 0
1957+
inst_len = 0
1958+
for plugin in plugins.keys():
1959+
md = extract_metadata(plugin)
1960+
name_len = max(name_len, len(plugin) + 1)
1961+
inst_len = max(inst_len, len(md['installed commit']) + 1)
1962+
for plugin in plugins.keys():
1963+
md = extract_metadata(plugin)
1964+
log.info(f"{plugin:<{name_len}} {md['installed commit']:<{inst_len}} {md['installation date']:<11} enabled")
1965+
plugins[plugin] = md
1966+
return plugins
1967+
1968+
19151969
def report_version() -> str:
19161970
"""return reckless version"""
19171971
log.info(__VERSION__)
@@ -2011,6 +2065,9 @@ if __name__ == '__main__':
20112065
update.add_argument('targets', type=str, nargs='*')
20122066
update.set_defaults(func=update_plugins)
20132067

2068+
list_cmd = cmd1.add_parser('list', help='list reckless-installed plugins')
2069+
list_cmd.set_defaults(func=listinstalled)
2070+
20142071
help_cmd = cmd1.add_parser('help', help='for contextual help, use '
20152072
'"reckless <cmd> -h"')
20162073
help_cmd.add_argument('targets', type=str, nargs='*')
@@ -2021,7 +2078,7 @@ if __name__ == '__main__':
20212078

20222079
all_parsers = [parser, install_cmd, uninstall_cmd, search_cmd, enable_cmd,
20232080
disable_cmd, list_parse, source_add, source_rem, help_cmd,
2024-
update]
2081+
update, list_cmd]
20252082
for p in all_parsers:
20262083
# This default depends on the .lightning directory
20272084
p.add_argument('-d', '--reckless-dir', action=StoreIdempotent,

0 commit comments

Comments
 (0)