@@ -1912,6 +1912,93 @@ def update_plugins(plugin_name: str):
19121912 return update_results
19131913
19141914
1915+ MD_FORMAT = {'installation date' : "None" ,
1916+ 'installation time' : "None" ,
1917+ 'original source' : "None" ,
1918+ 'requested commit' : "None" ,
1919+ 'installed commit' : "None" ,
1920+ }
1921+
1922+
1923+ def extract_metadata (plugin_name : str ) -> dict :
1924+ metadata_file = Path (RECKLESS_CONFIG .reckless_dir ) / plugin_name / '.metadata'
1925+ if not metadata_file .exists ():
1926+ return None
1927+
1928+ with open (metadata_file , 'r' ) as md :
1929+ lines = md .readlines ()
1930+ metadata = MD_FORMAT .copy ()
1931+ current_key = None
1932+
1933+ for line in lines :
1934+ if line .strip () in metadata :
1935+ current_key = line .strip ()
1936+ continue
1937+
1938+ if current_key :
1939+ metadata .update ({current_key : line .strip ()})
1940+ current_key = None
1941+
1942+ return metadata
1943+
1944+
1945+ def listinstalled ():
1946+ """list all plugins currently managed by reckless"""
1947+ dir_contents = os .listdir (RECKLESS_CONFIG .reckless_dir )
1948+ plugins = {}
1949+ for plugin in dir_contents :
1950+ if (Path (RECKLESS_CONFIG .reckless_dir ) / plugin ).is_dir ():
1951+ # skip hidden dirs such as reckless' .remote_sources
1952+ if plugin [0 ] == '.' :
1953+ continue
1954+ plugins .update ({plugin : None })
1955+
1956+ # Format output in a simple table
1957+ name_len = 0
1958+ inst_len = 0
1959+ for plugin in plugins .keys ():
1960+ md = extract_metadata (plugin )
1961+ name_len = max (name_len , len (plugin ) + 1 )
1962+ if md :
1963+ inst_len = max (inst_len , len (md ['installed commit' ]) + 1 )
1964+ else :
1965+ inst_len = max (inst_len , 5 )
1966+ for plugin in plugins .keys ():
1967+ md = extract_metadata (plugin )
1968+ # Older installed plugins may be missing a .metadata file
1969+ if not md :
1970+ md = MD_FORMAT .copy ()
1971+ try :
1972+ installed = InferInstall (plugin )
1973+ except :
1974+ log .debug (f'no plugin detected in directory { plugin } ' )
1975+ continue
1976+
1977+ status = "unmanaged"
1978+ for line in RECKLESS_CONFIG .content :
1979+ if installed .entry in line .strip () :
1980+ if line .strip ()[:7 ] == 'plugin=' :
1981+ status = "enabled"
1982+ elif line .strip ()[:15 ] == 'disable-plugin=' :
1983+ status = "disabled"
1984+ else :
1985+ print (f'cant handle { line } ' )
1986+ log .info (f"{ plugin :<{name_len }} { md ['installed commit' ]:<{inst_len }} "
1987+ f"{ md ['installation date' ]:<11} { status } " )
1988+ # This doesn't originate from the metadata, but we want to provide enabled status for json output
1989+ md ['enabled' ] = status == "enabled"
1990+ md ['entrypoint' ] = installed .entry
1991+ # Format for json output
1992+ for key in md :
1993+ if md [key ] == 'None' :
1994+ md [key ] = None
1995+ if key == 'installation time' and md [key ]:
1996+ md [key ] = int (md [key ])
1997+ plugins [plugin ] = md
1998+
1999+ return plugins
2000+
2001+
19152002def report_version () -> str :
19162003 """return reckless version"""
19172004 log .info (__VERSION__ )
@@ -2011,6 +2098,9 @@ if __name__ == '__main__':
20112098 update .add_argument ('targets' , type = str , nargs = '*' )
20122099 update .set_defaults (func = update_plugins )
20132100
2101+ list_cmd = cmd1 .add_parser ('list' , help = 'list reckless-installed plugins' )
2102+ list_cmd .set_defaults (func = listinstalled )
2103+
20142104 help_cmd = cmd1 .add_parser ('help' , help = 'for contextual help, use '
20152105 '"reckless <cmd> -h"' )
20162106 help_cmd .add_argument ('targets' , type = str , nargs = '*' )
@@ -2021,7 +2111,7 @@ if __name__ == '__main__':
20212111
20222112 all_parsers = [parser , install_cmd , uninstall_cmd , search_cmd , enable_cmd ,
20232113 disable_cmd , list_parse , source_add , source_rem , help_cmd ,
2024- update ]
2114+ update , list_cmd ]
20252115 for p in all_parsers :
20262116 # This default depends on the .lightning directory
20272117 p .add_argument ('-d' , '--reckless-dir' , action = StoreIdempotent ,
0 commit comments