@@ -7,76 +7,77 @@ local M = {
77 REF = " <REF>" ,
88}
99
10- -- For lists, the first value is the default value.
11- local arguments = {
12- action = {
13- type = M .LIST ,
14- values = {
15- " close" ,
16- " focus" ,
17- " show" ,
10+ M .setup = function (all_source_names )
11+ print (" all_source_names" , vim .inspect (all_source_names ))
12+ local source_names = utils .table_copy (all_source_names )
13+ table.insert (source_names , " migrations" )
14+
15+ -- For lists, the first value is the default value.
16+ local arguments = {
17+ action = {
18+ type = M .LIST ,
19+ values = {
20+ " close" ,
21+ " focus" ,
22+ " show" ,
23+ },
1824 },
19- },
20- position = {
21- type = M . LIST ,
22- values = {
23- " left " ,
24- " right " ,
25- -- "top ", --technically valid, but why show it if no one will use it?
26- -- "bottom", --technically valid, but why show it if no one will use it?
27- " float " ,
28- " current " ,
25+ position = {
26+ type = M . LIST ,
27+ values = {
28+ " left " ,
29+ " right " ,
30+ -- "top", --technically valid, but why show it if no one will use it?
31+ -- "bottom ", --technically valid, but why show it if no one will use it?
32+ " float " ,
33+ " current " ,
34+ } ,
2935 },
30- },
31- source = {
32- type = M .LIST ,
33- values = {
34- " filesystem" ,
35- " buffers" ,
36- " git_status" ,
37- " migrations" ,
36+ source = {
37+ type = M .LIST ,
38+ values = source_names ,
3839 },
39- },
40- dir = { type = M .PATH , stat_type = " directory" },
41- reveal_file = { type = M .PATH , stat_type = " file" },
42- git_base = { type = M .REF },
43- toggle = { type = M .FLAG },
44- reveal = { type = M .FLAG },
45- reveal_force_cwd = { type = M .FLAG },
46- }
40+ dir = { type = M .PATH , stat_type = " directory" },
41+ reveal_file = { type = M .PATH , stat_type = " file" },
42+ git_base = { type = M .REF },
43+ toggle = { type = M .FLAG },
44+ reveal = { type = M .FLAG },
45+ reveal_force_cwd = { type = M .FLAG },
46+ }
4747
48- local arg_type_lookup = {}
49- local list_args = {}
50- local path_args = {}
51- local ref_args = {}
52- local flag_args = {}
53- local reverse_lookup = {}
54- for name , def in pairs (arguments ) do
55- arg_type_lookup [name ] = def .type
56- if def .type == M .LIST then
57- table.insert (list_args , name )
58- for _ , vv in ipairs (def .values ) do
59- reverse_lookup [tostring (vv )] = name
48+ local arg_type_lookup = {}
49+ local list_args = {}
50+ local path_args = {}
51+ local ref_args = {}
52+ local flag_args = {}
53+ local reverse_lookup = {}
54+ for name , def in pairs (arguments ) do
55+ arg_type_lookup [name ] = def .type
56+ if def .type == M .LIST then
57+ table.insert (list_args , name )
58+ for _ , vv in ipairs (def .values ) do
59+ reverse_lookup [tostring (vv )] = name
60+ end
61+ elseif def .type == M .PATH then
62+ table.insert (path_args , name )
63+ elseif def .type == M .FLAG then
64+ table.insert (flag_args , name )
65+ reverse_lookup [name ] = M .FLAG
66+ elseif def .type == M .REF then
67+ table.insert (ref_args , name )
68+ else
69+ error (" Unknown type: " .. def .type )
6070 end
61- elseif def .type == M .PATH then
62- table.insert (path_args , name )
63- elseif def .type == M .FLAG then
64- table.insert (flag_args , name )
65- reverse_lookup [name ] = M .FLAG
66- elseif def .type == M .REF then
67- table.insert (ref_args , name )
68- else
69- error (" Unknown type: " .. def .type )
7071 end
71- end
7272
73- M .arguments = arguments
74- M .list_args = list_args
75- M .path_args = path_args
76- M .ref_args = ref_args
77- M .flag_args = flag_args
78- M .arg_type_lookup = arg_type_lookup
79- M .reverse_lookup = reverse_lookup
73+ M .arguments = arguments
74+ M .list_args = list_args
75+ M .path_args = path_args
76+ M .ref_args = ref_args
77+ M .flag_args = flag_args
78+ M .arg_type_lookup = arg_type_lookup
79+ M .reverse_lookup = reverse_lookup
80+ end
8081
8182M .resolve_path = function (path , validate_type )
8283 local expanded = vim .fn .expand (path )
@@ -101,7 +102,7 @@ local parse_arg = function(result, arg)
101102 if eq then
102103 local key = arg :sub (1 , eq - 1 )
103104 local value = arg :sub (eq + 1 )
104- local def = arguments [key ]
105+ local def = M . arguments [key ]
105106 if not def .type then
106107 error (" Invalid argument: " .. arg )
107108 end
@@ -126,7 +127,7 @@ local parse_arg = function(result, arg)
126127 end
127128 else
128129 local value = arg
129- local key = reverse_lookup [value ]
130+ local key = M . reverse_lookup [value ]
130131 if key == nil then
131132 -- maybe it's a git ref
132133 if M .verify_git_ref (value ) then
0 commit comments