Skip to content

Commit ce3a37a

Browse files
committed
feat: added --current-project-module parameter #34
1 parent 6f1ff13 commit ce3a37a

File tree

3 files changed

+116
-6
lines changed

3 files changed

+116
-6
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ To use vuh with your project you should first create .vuh file in root folder of
8888
If you want to execute command for multiple project modules you can
8989
specify them separated with commas (f.e. '-pm=API,WEB').
9090
If you want to execute command for all project modules you can write '-pm=ALL'.
91+
This parameter can't be used with '-cpm | --current-project-module'.
92+
93+
[-cpm | --current-project-module]
94+
to perform operations with current module of your mono repository project
95+
(in which dir you are located).
96+
This parameter can't be used with '-pm=<project_module>'.
9197

9298
[--dont-use-git] don't use any git commands.
9399
In this case you should run vuh in root directory (which contains .vuh)
@@ -108,6 +114,12 @@ To use vuh with your project you should first create .vuh file in root folder of
108114
If you want to execute command for multiple project modules you can
109115
specify them separated with commas (f.e. '-pm=API,WEB').
110116
If you want to execute command for all project modules you can write '-pm=ALL'.
117+
This parameter can't be used with '-cpm | --current-project-module'.
118+
119+
[-cpm | --current-project-module]
120+
to perform operations with current module of your mono repository project
121+
(in which dir you are located).
122+
This parameter can't be used with '-pm=<project_module>'.
111123

112124
[--offline | --airplane-mode]
113125
to work offline without updating origin/MAIN_BRANCH_NAME
@@ -130,6 +142,12 @@ To use vuh with your project you should first create .vuh file in root folder of
130142
If you want to execute command for multiple project modules you can
131143
specify them separated with commas (f.e. '-pm=API,WEB').
132144
If you want to execute command for all project modules you can write '-pm=ALL'.
145+
This parameter can't be used with '-cpm | --current-project-module'.
146+
147+
[-cpm | --current-project-module]
148+
to perform operations with current module of your mono repository project
149+
(in which dir you are located).
150+
This parameter can't be used with '-pm=<project_module>'.
133151

134152
[--check-git-diff] to automatically increase version only if current branch has git difference
135153
with HEAD..origin/MAIN_BRANCH_NAME. And if there is no git difference vuh will not
@@ -178,6 +196,12 @@ To use vuh with your project you should first create .vuh file in root folder of
178196
If you want to execute command for multiple project modules you can
179197
specify them separated with commas (f.e. '-pm=API,WEB').
180198
If you want to execute command for all project modules you can write '-pm=ALL'.
199+
This parameter can't be used with '-cpm | --current-project-module'.
200+
201+
[-cpm | --current-project-module]
202+
to perform operations with current module of your mono repository project
203+
(in which dir you are located).
204+
This parameter can't be used with '-pm=<project_module>'.
181205

182206
[--check-git-diff] to automatically increase version only if current branch has git difference
183207
with HEAD..origin/MAIN_BRANCH_NAME. And if there is no git difference vuh will not
@@ -217,6 +241,12 @@ To use vuh with your project you should first create .vuh file in root folder of
217241
If you want to execute command for multiple project modules you can
218242
specify them separated with commas (f.e. '-pm=API,WEB').
219243
If you want to execute command for all project modules you can write '-pm=ALL'.
244+
This parameter can't be used with '-cpm | --current-project-module'.
245+
246+
[-cpm | --current-project-module]
247+
to perform operations with current module of your mono repository project
248+
(in which dir you are located).
249+
This parameter can't be used with '-pm=<project_module>'.
220250

221251
[--dont-use-git] don't use any git commands.
222252
In this case you should run vuh in root directory (which contains .vuh)

vuh-completion.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ function _vuh_completion()
2323
words=""
2424
;;
2525
lv|local-version)
26-
words="-q -pm= --quiet --dont-use-git --config-dir="
26+
words="-q -pm= -cpm --current-project-module --quiet --dont-use-git --config-dir="
2727
;;
2828
mv|main-version)
29-
words="-q -mb= -pm= --quiet --offline --airplane-mode --dont-use-git --config-dir="
29+
words="-q -mb= -pm= -cpm --current-project-module --quiet --offline --airplane-mode --dont-use-git --config-dir="
3030
;;
3131
sv|suggest-version)
32-
words="-q -v= -vp= -mb= -pm= --quiet --check-git-diff --dont-check-git-diff --offline --airplane-mode --dont-use-git --config-dir="
32+
words="-q -v= -vp= -mb= -pm= -cpm --current-project-module --quiet --check-git-diff --dont-check-git-diff --offline --airplane-mode --dont-use-git --config-dir="
3333
;;
3434
uv|update-version)
35-
words="'-q ' -v= -vp= -mb= -pm= '--quiet ' '--check-git-diff ' '--dont-check-git-diff ' '--offline ' '--airplane-mode ' '--dont-use-git ' --config-dir="
35+
words="-q -v= -vp= -mb= -pm= -cpm --current-project-module --quiet --check-git-diff --dont-check-git-diff --offline --airplane-mode --dont-use-git --config-dir="
36+
# words="'-q ' -v= -vp= -mb= -pm= '-cpm ' '--current-project-module ' '--quiet ' '--check-git-diff ' '--dont-check-git-diff ' '--offline ' '--airplane-mode ' '--dont-use-git ' --config-dir="
3637
;;
3738
mrp|module-root-path)
38-
words="-q -pm= --quiet --dont-use-git --config-dir="
39+
words="-q -pm= -cpm --current-project-module --quiet --dont-use-git --config-dir="
3940
;;
4041
pm|project-modules)
4142
words="-q --quiet --dont-use-git --config-dir="

vuh.sh

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
#/ If you want to execute command for multiple project modules you can
1919
#/ specify them separated with commas (f.e. '-pm=API,WEB').
2020
#/ If you want to execute command for all project modules you can write '-pm=ALL'.
21+
#/ This parameter can't be used with '-cpm | --current-project-module'.
22+
#/
23+
#/ [-cpm | --current-project-module]
24+
#/ to perform operations with current module of your mono repository project
25+
#/ (in which dir you are located).
26+
#/ This parameter can't be used with '-pm=<project_module>'.
2127
#/
2228
#/ [--dont-use-git] don't use any git commands.
2329
#/ In this case you should run vuh in root directory (which contains .vuh)
@@ -38,6 +44,12 @@
3844
#/ If you want to execute command for multiple project modules you can
3945
#/ specify them separated with commas (f.e. '-pm=API,WEB').
4046
#/ If you want to execute command for all project modules you can write '-pm=ALL'.
47+
#/ This parameter can't be used with '-cpm | --current-project-module'.
48+
#/
49+
#/ [-cpm | --current-project-module]
50+
#/ to perform operations with current module of your mono repository project
51+
#/ (in which dir you are located).
52+
#/ This parameter can't be used with '-pm=<project_module>'.
4153
#/
4254
#/ [--offline | --airplane-mode]
4355
#/ to work offline without updating origin/MAIN_BRANCH_NAME
@@ -60,6 +72,12 @@
6072
#/ If you want to execute command for multiple project modules you can
6173
#/ specify them separated with commas (f.e. '-pm=API,WEB').
6274
#/ If you want to execute command for all project modules you can write '-pm=ALL'.
75+
#/ This parameter can't be used with '-cpm | --current-project-module'.
76+
#/
77+
#/ [-cpm | --current-project-module]
78+
#/ to perform operations with current module of your mono repository project
79+
#/ (in which dir you are located).
80+
#/ This parameter can't be used with '-pm=<project_module>'.
6381
#/
6482
#/ [--check-git-diff] to automatically increase version only if current branch has git difference
6583
#/ with HEAD..origin/MAIN_BRANCH_NAME. And if there is no git difference vuh will not
@@ -108,6 +126,12 @@
108126
#/ If you want to execute command for multiple project modules you can
109127
#/ specify them separated with commas (f.e. '-pm=API,WEB').
110128
#/ If you want to execute command for all project modules you can write '-pm=ALL'.
129+
#/ This parameter can't be used with '-cpm | --current-project-module'.
130+
#/
131+
#/ [-cpm | --current-project-module]
132+
#/ to perform operations with current module of your mono repository project
133+
#/ (in which dir you are located).
134+
#/ This parameter can't be used with '-pm=<project_module>'.
111135
#/
112136
#/ [--check-git-diff] to automatically increase version only if current branch has git difference
113137
#/ with HEAD..origin/MAIN_BRANCH_NAME. And if there is no git difference vuh will not
@@ -147,6 +171,12 @@
147171
#/ If you want to execute command for multiple project modules you can
148172
#/ specify them separated with commas (f.e. '-pm=API,WEB').
149173
#/ If you want to execute command for all project modules you can write '-pm=ALL'.
174+
#/ This parameter can't be used with '-cpm | --current-project-module'.
175+
#/
176+
#/ [-cpm | --current-project-module]
177+
#/ to perform operations with current module of your mono repository project
178+
#/ (in which dir you are located).
179+
#/ This parameter can't be used with '-pm=<project_module>'.
150180
#/
151181
#/ [--dont-use-git] don't use any git commands.
152182
#/ In this case you should run vuh in root directory (which contains .vuh)
@@ -177,7 +207,7 @@
177207
# Written by Shishkin Sergey <[email protected]>
178208

179209
# Current vuh version
180-
VUH_VERSION='2.10.0'
210+
VUH_VERSION='2.11.0'
181211

182212
# Installation variables (Please don't modify!)
183213
DATA_DIR='<should_be_replace_after_installation:DATA_DIR>'
@@ -219,6 +249,8 @@ SPECIFIED_INCREASING_VERSION_PART='patch'
219249
SPECIFIED_PROJECT_MODULE=''
220250
SPECIFIED_MAIN_BRANCH=''
221251
SPECIFIED_CONFIG_DIR=''
252+
ARGUMENT_SPECIFIED_PROJECT_MODULE='false'
253+
ARGUMENT_USE_CURRENT_PROJECT_MODULE='false'
222254
ARGUMENT_QUIET='false'
223255
ARGUMENT_CHECK_GIT_DIFF='false'
224256
ARGUMENT_DONT_CHECK_GIT_DIFF='false'
@@ -421,6 +453,12 @@ function _load_project_variables_from_config() {
421453
rm -f "/tmp/${APP_NAME}_projects_conf_file"
422454
return 1
423455
}
456+
if [ "$ARGUMENT_USE_CURRENT_PROJECT_MODULE" = 'true' ]; then
457+
SPECIFIED_PROJECT_MODULE=$(_get_project_module_for_current_directory) || {
458+
_show_error_message "Failed to get project module! Current directory doesn't belong to any project module."
459+
return 1
460+
}
461+
fi
424462
rm -f "/tmp/${APP_NAME}_projects_conf_file"
425463
[ "$SPECIFIED_MULTIPLE_PROJECT_MODULES" = 'true' ] || _use_module_configuration_if_it_exists "$SPECIFIED_PROJECT_MODULE"
426464
}
@@ -689,6 +727,40 @@ function _get_version_from_file() {
689727
echo "$version"
690728
}
691729

730+
function _get_project_module_for_current_directory() {
731+
handling_dir="$CUR_DIR"
732+
found_module='false'
733+
keep_searching='true'
734+
handling_module_root_path=''
735+
while [ "$keep_searching" = 'true' ]; do
736+
# TODO handle case when one module is subdir of another module
737+
project_modules_without_spaces=$(echo "$PROJECT_MODULES" | tr -d "[:space:]")
738+
IFS=',' read -ra ADDR <<< "$project_modules_without_spaces"
739+
for module in "${ADDR[@]}"; do
740+
eval handling_module_root_path='$'"$module"'_MODULE_ROOT_PATH'
741+
module_root_dir_for_find="$ROOT_REPO_DIR"
742+
if [ "$handling_module_root_path" != '' ]; then
743+
module_root_dir_for_find="$module_root_dir_for_find/$handling_module_root_path"
744+
fi
745+
find_result=$(find "$module_root_dir_for_find" -type d -wholename "$handling_dir")
746+
if [ "$find_result" != '' ]; then
747+
echo "$module"
748+
found_module='true'
749+
keep_searching='false'
750+
fi
751+
# _use_module_configuration "$next_handling_module" || return 1
752+
done
753+
if [ "$handling_dir" = '/' ] || [ "$handling_dir" = "$ROOT_REPO_DIR" ]; then
754+
keep_searching='false'
755+
fi
756+
handling_dir="$(dirname "$handling_dir")"
757+
done
758+
if [ "$found_module" = 'false' ]; then
759+
_show_error_message "Failed to get any module root path which could contain your current path!"
760+
return 1
761+
fi
762+
}
763+
692764
function _fetch_remote_branches() {
693765
git fetch -q || {
694766
_show_error_message 'Failed to use "git fetch" to update information about remote branches!'
@@ -1226,6 +1298,8 @@ while [[ $# -gt 0 ]]; do
12261298
shift ;;
12271299
-pm=*)
12281300
_check_arg "$1"
1301+
_show_cant_use_both_arguments '--current-project-module' '-pm=' "$ARGUMENT_USE_CURRENT_PROJECT_MODULE" 'false'
1302+
ARGUMENT_SPECIFIED_PROJECT_MODULE='true'
12291303
SPECIFIED_PROJECT_MODULE=${1#*=}
12301304
if [[ "$SPECIFIED_PROJECT_MODULE" == *","* ]]; then
12311305
SPECIFIED_MULTIPLE_PROJECT_MODULES='true'
@@ -1234,6 +1308,11 @@ while [[ $# -gt 0 ]]; do
12341308
SPECIFIED_MULTIPLE_PROJECT_MODULES='true'
12351309
fi
12361310
shift ;;
1311+
-cpm|--current-project-module)
1312+
_check_arg "$1"
1313+
_show_cant_use_both_arguments '-pm=' '--current-project-module' "$ARGUMENT_SPECIFIED_PROJECT_MODULE" 'false'
1314+
ARGUMENT_USE_CURRENT_PROJECT_MODULE='true'
1315+
shift ;;
12371316
-q|--quiet)
12381317
_check_arg "$1"
12391318
ARGUMENT_QUIET='true'

0 commit comments

Comments
 (0)