@@ -33,7 +33,7 @@ def generate_variants (list_of_variant_list):
3333# This makes it so that user don't have to remember much about the commands, as
3434# whatever they think is the right command is likely an accepted variant of it.
3535
36- rm_variants = ['rm' , 'remove' , 'clear' , 'del' , 'delete ' ]
36+ add_variants = ['add ' ]
3737desc_variants = ['desc' , 'description' ]
3838dir_variants = [
3939 'dir' ,
@@ -47,34 +47,37 @@ def generate_variants (list_of_variant_list):
4747 'folder' ,
4848 'folders'
4949]
50- up_variants = ['up ' , 'update ' ]
50+ ena_variants = ['ena ' , 'enabled ' ]
5151for_variants = ['for' , 'foreach' , 'for-all' ]
52+ from_official_variants = ['from-official' ]
53+ help_variants = ['help' , '-h' , '--help' ]
54+ list_variants = ['list' , 'ls' ]
5255rec_variants = ['rec' , 'recursive' ]
53- ena_variants = ['ena' , 'enabled' ]
54- add_variants = ["add" ]
55- help_variants = ["help" , "-h" , "--help" ]
56- seek_variants = ["seek" , "suggest" ]
57- status_variants = ["status" , "info" ]
58- from_official_variants = ["from-official" ]
59- to_official_variants = ["to-official" ]
56+ rm_variants = ['rm' , 'remove' , 'clear' , 'del' , 'delete' ]
57+ seek_variants = ['seek' , 'suggest' ]
58+ status_variants = ['status' , 'info' ]
59+ to_official_variants = ['to-official' ]
60+ up_variants = ['up' , 'update' ]
6061
6162aliases = dict ()
6263aliases ['add' ] = add_variants
63- aliases ['help' ] = help_variants
64- aliases ['seek' ] = seek_variants
65- aliases ['status' ] = status_variants
64+ aliases ['foreach' ] = for_variants
65+ aliases ['foreach-enabled' ] = generate_variants ([for_variants , ena_variants ])
66+ aliases ['foreach-enabled-recursive' ] = (
67+ generate_variants ([for_variants , ena_variants , rec_variants ])
68+ )
69+ aliases ['foreach-recursive' ] = generate_variants ([for_variants , rec_variants ])
6670aliases ['from-official' ] = from_official_variants
67- aliases ['to-official' ] = to_official_variants
71+ aliases ['help' ] = help_variants
72+ aliases ['list' ] = list_variants
6873aliases ['rm' ] = rm_variants
6974aliases ['rm-desc' ] = generate_variants ([rm_variants , desc_variants ])
7075aliases ['rm-dir' ] = generate_variants ([rm_variants , dir_variants ])
76+ aliases ['seek' ] = seek_variants
77+ aliases ['status' ] = status_variants
78+ aliases ['to-official' ] = to_official_variants
7179aliases ['up-desc' ] = generate_variants ([up_variants , desc_variants ])
7280aliases ['up-dir' ] = generate_variants ([up_variants , dir_variants ])
73- aliases ['foreach-recursive' ] = generate_variants ([for_variants , rec_variants ])
74- aliases ['foreach-enabled' ] = generate_variants ([for_variants , ena_variants ])
75- aliases ['foreach-enabled-recursive' ] = (
76- generate_variants ([for_variants , ena_variants , rec_variants ])
77- )
7881
7982################################################################################
8083##### OS COMMANDS ##############################################################
@@ -1391,6 +1394,24 @@ def handle_generic_help (invocation):
13911394 print ("EFFECT provides detailed help about a command." )
13921395 print ("" )
13931396 print ("################" )
1397+ print ("COMMAND list" )
1398+ print (
1399+ "PARAMETERS list of local paths. The root repository's path is selected"
1400+ " if no path is given"
1401+ )
1402+ print ("EFFECT lists all submodules in those directories." )
1403+ print ("" )
1404+ print ("################" )
1405+ print ("COMMAND from-official" )
1406+ print (
1407+ "PARAMETERS list of local paths to official Git Submodules. All"
1408+ " official Git Submdule are selected if no path is given."
1409+ )
1410+ print (
1411+ "EFFECT updates the description to include the selected official Git"
1412+ " Submodules. These do not need to have been initialized."
1413+ )
1414+ print ("################" )
13941415 print ("COMMAND remove" )
13951416 print (
13961417 "PARAMETERS list of paths to submodules. All described submodules are"
@@ -1621,6 +1642,17 @@ def handle_help_command (invocation, parameters):
16211642
16221643 return
16231644
1645+ if (command in aliases ['list' ]):
1646+ print (
1647+ "PARAMETERS list of local paths. The root repository's path is"
1648+ " selected if no path is given"
1649+ )
1650+ print ("EFFECT lists all submodules in those directories." )
1651+ print ("EXAMPLE list" )
1652+ print ("EXAMPLE list ./my" )
1653+ print ("EXAMPLE list ./my my_other_folder" )
1654+ print ("ALIASES " + ', ' .join (aliases ['list' ]) + "." )
1655+
16241656 if (command in aliases ['rm' ]):
16251657 # TODO
16261658 print ("EXAMPLE remove ./my/src/local_clone" )
@@ -1629,42 +1661,49 @@ def handle_help_command (invocation, parameters):
16291661 return
16301662
16311663 if (command in aliases ['rm-desc' ]):
1664+ # TODO
16321665 print ("EXAMPLE remove-description ./my/src/local_clone" )
16331666 print ("ALIASES " + ', ' .join (aliases ['rm-desc' ]) + "." )
16341667
16351668 return
16361669
16371670 if (command in aliases ['rm-dir' ]):
1671+ # TODO
16381672 print ("EXAMPLE remove-description ./my/src/local_clone" )
16391673 print ("ALIASES " + ', ' .join (aliases ['rm-dir' ]) + "." )
16401674
16411675 return
16421676
16431677 if (command in aliases ['seek' ]):
1678+ # TODO
16441679 print ("EXAMPLE seek /my/src/" )
16451680 print ("ALIASES " + ', ' .join (aliases ['seek' ]) + "." )
16461681
16471682 return
16481683
16491684 if (command in aliases ['status' ]):
1685+ # TODO
16501686 print ("EXAMPLE status /my/src/local_clone" )
16511687 print ("ALIASES " + ', ' .join (aliases ['status' ]) + "." )
16521688
16531689 return
16541690
16551691 if (command in aliases ['to-official' ]):
1692+ # TODO
16561693 print ("EXAMPLE to-official /my/src/local_clone" )
16571694 print ("ALIASES " + ', ' .join (aliases ['to-official' ]) + "." )
16581695
16591696 return
16601697
16611698 if (command in aliases ['up-desc' ]):
1699+ # TODO
16621700 print ("EXAMPLE update-description /my/src/local_clone" )
16631701 print ("ALIASES " + ', ' .join (aliases ['up-desc' ]) + "." )
16641702
16651703 return
16661704
16671705 if (command in aliases ['up-dir' ]):
1706+ # TODO
16681707 print ("EXAMPLE update-directory /my/src/local_clone" )
16691708 print ("ALIASES " + ', ' .join (aliases ['up-dir' ]) + "." )
16701709
@@ -1932,6 +1971,31 @@ def handle_status_command (paths):
19321971
19331972 apply_check_to (submodule_dictionary , root_directory )
19341973
1974+ ################################################################################
1975+ ##### LIST #####################################################################
1976+ ################################################################################
1977+ def handle_list_command (paths ):
1978+ current_directory = os .getcwd ()
1979+ root_directory = git_find_root_path ()
1980+
1981+ (submodule_list , submodule_dictionary ) = get_submodules_of (root_directory )
1982+
1983+ paths = [
1984+ resolve_relative_path (
1985+ root_directory ,
1986+ current_directory ,
1987+ path .rstrip (os .sep )
1988+ ) for path in paths
1989+ ]
1990+
1991+ if (len (paths ) == 0 ):
1992+ paths = ["" ]
1993+
1994+ for submodule_path in submodule_dictionary :
1995+ for path in paths :
1996+ if (submodule_path .startswith (path )):
1997+ print (submodule_path )
1998+
19351999################################################################################
19362000##### TO OFFICIAL ##############################################################
19372001################################################################################
@@ -2031,6 +2095,10 @@ def handle_update_directory_command (paths):
20312095 handle_from_official_command (sys .argv [2 :])
20322096 sys .exit (0 )
20332097
2098+ if (command in aliases ['list' ]):
2099+ handle_list_command (sys .argv [2 :])
2100+ sys .exit (0 )
2101+
20342102if (command in aliases ['rm' ]):
20352103 handle_remove_command (sys .argv [2 :])
20362104 sys .exit (0 )
@@ -2066,157 +2134,3 @@ def handle_update_directory_command (paths):
20662134print ("[F] Unknown command \" " + command + "\" ." , file = sys .stderr )
20672135handle_generic_help (sys .argv [0 ])
20682136sys .exit (- 1 )
2069-
2070-
2071- if (args .cmd [0 ] in aliases ['seek' ]):
2072- args .paths = [
2073- resolve_absolute_path (root_directory , current_directory , path )
2074- for path in args .paths
2075- ]
2076- args .paths = [
2077- path
2078- for path in args .paths if (
2079- os .path .isdir (path ) and (path != root_directory )
2080- )
2081- ]
2082-
2083- if (len (args .paths ) == 0 ):
2084- args .paths = get_path_of_direct_subdirectories (root_directory , [".git" ])
2085-
2086- list_all_non_submodule_subrepositories (
2087- submodule_dictionary ,
2088- args .paths ,
2089- root_directory
2090- )
2091-
2092- sys .exit (0 )
2093-
2094- foreach_command = None
2095-
2096- if (
2097- (args .cmd [0 ] in aliases ['foreach' ])
2098- or (args .cmd [0 ] in aliases ['foreach-recursive' ])
2099- or (args .cmd [0 ] in aliases ['foreach-enabled' ])
2100- or (args .cmd [0 ] in aliases ['foreach-enabled-recursive' ])
2101- ):
2102- if (len (args .paths ) == 0 ):
2103- print (
2104- "[F] "
2105- + args .cmd [0 ]
2106- + " requires at least one more parameter." ,
2107- file = sys .stderr
2108- )
2109-
2110- sys .exit (- 1 )
2111-
2112- foreach_command = args .paths .pop ()
2113-
2114- args .paths = [
2115- resolve_relative_path (
2116- root_directory ,
2117- current_directory ,
2118- path .rstrip (os .sep )
2119- ) for path in args .paths
2120- ]
2121-
2122- if (args .cmd [0 ] in aliases ['rm-desc' ]):
2123- if (len (args .paths ) == 0 ):
2124- args .paths = [path for path in submodule_dictionary ]
2125-
2126- update_submodules_desc_file (root_directory , dict (), args .paths )
2127-
2128- sys .exit (0 )
2129-
2130- if (args .cmd [0 ] in aliases ['from-official' ]):
2131- if (len (args .paths ) == 0 ):
2132- print ("Shallow initialization of all Official Git Submodules..." )
2133- git_shallow_submodule_init (root_directory , "." )
2134- print ("Done." )
2135- args .paths = git_get_official_submodule_paths (root_directory )
2136- else :
2137- for path in args .paths :
2138- print (
2139- "Shallow Official Git Submodule initialization for \" "
2140- + path
2141- + "\" ..."
2142- )
2143- git_shallow_submodule_init (root_directory , path )
2144- print ("Done." )
2145-
2146- if (path not in git_get_official_submodule_paths (root_directory )):
2147- print (
2148- "[F] No Official Git Submodule registered at \" "
2149- + path
2150- + "\" ." ,
2151- file = sys .stderr
2152- )
2153- sys .exit (- 1 )
2154-
2155-
2156- args .cmd [0 ] = "add"
2157-
2158- if (args .cmd [0 ] in aliases ['add' ]):
2159- for path in args .paths :
2160- if (path not in submodule_dictionary ):
2161- new_module = GitSubmodule (path )
2162- submodule_dictionary [path ] = new_module
2163- submodule_list .append (new_module )
2164-
2165- args .cmd [0 ] = "update-desc"
2166-
2167- if (submodule_list == []):
2168- print ("[F] No submodules in " + root_directory + "." , file = sys .stderr )
2169- sys .exit (- 1 )
2170-
2171- submodule_dictionary = restrict_dictionary_to (submodule_dictionary , args .paths )
2172-
2173- if (foreach_command is not None ):
2174- is_recursive = False
2175- is_enabled_only = False
2176-
2177- if (args .cmd [0 ] in aliases ['foreach-recursive' ]):
2178- is_recursive = True
2179- elif (args .cmd [0 ] in aliases ['foreach-enabled' ]):
2180- is_enabled_only = True
2181- elif (args .cmd [0 ] in aliases ['foreach-enabled-recursive' ]):
2182- is_enabled_only = True
2183- is_recursive = True
2184-
2185- apply_foreach_to (
2186- submodule_dictionary ,
2187- is_recursive ,
2188- is_enabled_only ,
2189- [root_directory ], # = traversed_submodules
2190- foreach_command ,
2191- root_directory
2192- )
2193- elif (args .cmd [0 ] in aliases ['up-dir' ]):
2194- apply_clone_to (submodule_dictionary , root_directory )
2195- git_add_to_gitignore (
2196- set ([path for path in submodule_dictionary ]),
2197- root_directory
2198- )
2199- elif (args .cmd [0 ] in aliases ['status' ]):
2200- apply_check_to (submodule_dictionary , root_directory )
2201- elif (args .cmd [0 ] in aliases ['rm' ]):
2202- if (len (args .paths ) == 0 ):
2203- args .paths = [path for path in submodule_dictionary ]
2204-
2205- update_submodules_desc_file (root_directory , dict (), args .paths )
2206- apply_clear_to (submodule_dictionary , root_directory )
2207- elif (args .cmd [0 ] in aliases ['rm-dir' ]):
2208- apply_clear_to (submodule_dictionary , root_directory )
2209- elif (args .cmd [0 ] in aliases ['up-desc' ]):
2210- apply_update_desc_to (submodule_dictionary , root_directory )
2211-
2212- update_submodules_desc_file (root_directory , submodule_dictionary , [])
2213-
2214- print ("updated description written." )
2215-
2216- git_add_to_gitignore (
2217- set ([path for path in submodule_dictionary ]),
2218- root_directory
2219- )
2220- else :
2221- print ("[F] Unknown command \" " + args .cmd [0 ] + "\" ." , file = sys .stderr )
2222- sys .exit (- 1 )
0 commit comments