Skip to content

Commit db17e8d

Browse files
committed
mud get-config command added
1 parent 0a17f4b commit db17e8d

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ paru -S mud-git
2525
1. Run `mud config` to start interactive wizard which help you to set the preferable settings. Check [settings](#settings) section for more. At the end, `.mudsettings` file will appear at your home directory that you can alter in the future.
2626
2. Locate to your preferable directory with repositories.
2727
3. Run `mud init` command to create `.mudconfig` file. This file is important to keep references to repositories. All repositories in current dictionary would be included to `.mudconfig`.
28-
4. Optional: Run [`mud --set-global`](#global-mudconfig) to make current configuration default and reachable from any directory.
28+
4. Optional: Run [`mud set-global`](#commands) to make current configuration default and reachable from any directory.
2929

3030
All entries are stored in `.mudconfig` in TSV format. After making your first entry, you can open `.mudconfig` in a text editor and modify it according to your needs.
3131

32-
### Global .mudconfig
33-
- `mud --set-global` - sets current `.mudconfig` as a global configuration, so it would be used as a fallback configuration to run from any directory.
34-
3532
## Using
3633

3734
### Commands
38-
`mud <FILTER> <COMMAND>` will execute bash command across all repositories. To filter repositories check [arguments](#arguments) section.
3935

36+
- `mud set-global` - sets current `.mudconfig` as a global configuration, so it would be used as a fallback configuration to run from any directory.
37+
- `mud get-config` - prints closest `.mudconfig` location.
38+
39+
`mud <FILTER> <COMMAND>` will execute bash command across all repositories. To filter repositories check [arguments](#arguments) section.
4040
- `mud info`/`mud i` - displays branch divergence and working directory changes.
4141
- `mud status`/`mud st` - displays working directory changes.
4242
- `mud log`/`mud l` - displays latest commit message, it's time and it's author.
@@ -59,8 +59,11 @@ All entries are stored in `.mudconfig` in TSV format. After making your first en
5959
Example:
6060

6161
```bash
62-
mud -b=master -d git pull
6362
# Filters out all repos with master branch and diverged branches and then runs pull command.
63+
mud -b=master -d git pull
64+
65+
# Fetches all repositories that are not on master branch and have "personal" label but excluding ones with "work" label
66+
mud -nb=master -l=personal -nl=work git fetch
6467
```
6568

6669
## Settings

src/mud/app.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ def __init__(self):
2323

2424
@staticmethod
2525
def _create_parser() -> ArgumentParser:
26-
parser = argparse.ArgumentParser(description=f'{BOLD}mud{RESET} allows you to run commands in multiple repositories.')
26+
parser = argparse.ArgumentParser(description=f'mud allows you to run commands in multiple repositories.')
2727
subparsers = parser.add_subparsers(dest='command')
2828

2929
subparsers.add_parser(LOG[0], aliases=LOG[1:], help='Displays log of latest commit messages for all repositories in a table view.')
3030
subparsers.add_parser(INFO[0], aliases=INFO[1:], help='Displays branch divergence and working directory changes')
31-
subparsers.add_parser(INIT[0], aliases=INIT[1:], help=f'Initializes the {BOLD}.mudconfig{RESET} and adds all repositories in this directory to {BOLD}.mudconfig{RESET}.')
31+
subparsers.add_parser(INIT[0], aliases=INIT[1:], help=f'Initializes the .mudconfig and adds all repositories in this directory to .mudconfig.')
3232
subparsers.add_parser(TAGS[0], aliases=TAGS[1:], help='Displays git tags in repositories.')
3333
subparsers.add_parser(LABELS[0], aliases=LABELS[1:], help='Displays mud labels across repositories.')
3434
subparsers.add_parser(STATUS[0], aliases=STATUS[1:], help='Displays working directory changes.')
3535
subparsers.add_parser(BRANCHES[0], aliases=BRANCHES[1:], help='Displays all branches in repositories.')
3636
subparsers.add_parser(REMOTE_BRANCHES[0], aliases=REMOTE_BRANCHES[1:], help='Displays all remote branches in repositories.')
3737
subparsers.add_parser(CONFIGURE[0], aliases=CONFIGURE[1:], help='Runs the interactive configuration wizard.')
38+
subparsers.add_parser(GET_CONFIG[0], aliases=GET_CONFIG[1:], help='Prints current .mudconfig path.')
3839

3940
add_parser = subparsers.add_parser(ADD[0], aliases=ADD[1:], help='Adds repository or labels an existing repository.')
4041
add_parser.add_argument('label', help='The label to add (optional).', nargs='?', default='', type=str)
@@ -53,7 +54,7 @@ def _create_parser() -> ArgumentParser:
5354
parser.add_argument(*MODIFIED_ATTR, action='store_true', help='Filters modified repositories.')
5455
parser.add_argument(*DIVERGED_ATTR, action='store_true', help='Filters repositories with diverged branches.')
5556
parser.add_argument(*ASYNC_ATTR, action='store_true', help='Switches asynchronous run feature.')
56-
parser.add_argument(SET_GLOBAL[0], help=f'Sets {BOLD}.mudconfig{RESET} in the current repository as your fallback {BOLD}.mudconfig{RESET}.', action='store_true')
57+
parser.add_argument(SET_GLOBAL[0], help=f'Sets .mudconfig in the current repository as your fallback .mudconfig.', action='store_true')
5758
parser.add_argument('catch_all', help='Type any commands to execute among repositories.', nargs='*')
5859
return parser
5960

@@ -66,11 +67,19 @@ def run(self) -> None:
6667
return
6768
# Sets global repository in .mudsettings
6869
if sys.argv[1] in SET_GLOBAL:
69-
config_path = os.path.join(os.getcwd(), utils.CONFIG_FILE_NAME)
70+
if len(sys.argv) > 2:
71+
config_path = sys.argv[2]
72+
if not os.path.isabs(config_path):
73+
config_path = os.path.abspath(config_path)
74+
else:
75+
config_path = os.path.join(os.getcwd(), utils.CONFIG_FILE_NAME)
76+
7077
if os.path.exists(config_path):
7178
utils.settings.config.set('mud', 'config_path', config_path)
7279
utils.settings.save()
73-
print(f'Current {BOLD}.mudconfig{RESET} set as a global configuration.')
80+
print(f'{config_path} set as a global.')
81+
else:
82+
utils.print_error(f'File {config_path} not found')
7483
return
7584
# Runs configuration wizard
7685
elif sys.argv[1] in CONFIGURE:
@@ -85,7 +94,13 @@ def run(self) -> None:
8594
self.init(self.parser.parse_args())
8695
return
8796

88-
self.config.find()
97+
config_path = self.config.find()
98+
99+
# Prints current config path
100+
if sys.argv[1] in GET_CONFIG:
101+
print(config_path)
102+
return
103+
89104
self._filter_with_arguments()
90105

91106
self.cmd_runner = Runner(self.config)

src/mud/commands.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
REMOTE_BRANCHES = ['remote-branch', 'remote-branches', 'rbr']
1212
HELP = ['help', '--help', '-h']
1313
CONFIGURE = ['configure', 'config']
14-
SET_GLOBAL = ['--set-global']
14+
GET_CONFIG = ['get-config']
15+
SET_GLOBAL = ['set-global']
1516

16-
COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, CONFIGURE, SET_GLOBAL]
17+
COMMANDS = [ADD, REMOVE, LOG, INFO, INIT, TAGS, LABELS, STATUS, BRANCHES, REMOTE_BRANCHES, HELP, CONFIGURE, SET_GLOBAL, GET_CONFIG]
1718

1819
# Filters
1920
ASYNC_ATTR = '-a', '--async'

src/mud/config.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,24 @@ def _filter_labels(label: str):
2424
formatted_labels = ','.join(valid_labels) if valid_labels else ''
2525
writer.writerow([path, formatted_labels])
2626

27-
def find(self) -> None:
28-
if os.path.exists(utils.CONFIG_FILE_NAME):
29-
self.load(utils.CONFIG_FILE_NAME)
30-
return
31-
27+
def find(self) -> str:
3228
directory = os.getcwd()
3329
current_path = directory
3430
while os.path.dirname(current_path) != current_path:
3531
os.chdir(current_path)
3632
if os.path.exists(utils.CONFIG_FILE_NAME):
3733
self.load(utils.CONFIG_FILE_NAME)
38-
return utils.CONFIG_FILE_NAME
34+
return current_path
3935
current_path = os.path.dirname(current_path)
4036

41-
if utils.settings.mud_settings['config_path'] != '' and os.path.exists(
42-
utils.settings.mud_settings['config_path']):
37+
if utils.settings.mud_settings['config_path'] != '' and os.path.exists(utils.settings.mud_settings['config_path']):
4338
directory = os.path.dirname(utils.settings.mud_settings['config_path'])
4439
os.chdir(directory)
4540
os.environ['PWD'] = directory
4641
self.load(utils.CONFIG_FILE_NAME)
47-
return
42+
return current_path
4843

49-
utils.print_error(f'{BOLD}{utils.CONFIG_FILE_NAME}{RESET} was not found. Type `mud init` to create configuration file.', 11, exit=True)
50-
return
44+
utils.print_error(f'{BOLD}{utils.CONFIG_FILE_NAME}{RESET} was not found. Run \'mud init\' to create a configuration file.', 11, exit=True)
5145

5246
def load(self, file_path: str) -> None:
5347
self.data = {}

0 commit comments

Comments
 (0)