Skip to content

Commit 90f80f9

Browse files
authored
feat: integrate init --no-feature to the workflow
For more information, read : #51 (comment)
2 parents 854445e + 7d379b0 commit 90f80f9

File tree

6 files changed

+96
-10
lines changed

6 files changed

+96
-10
lines changed

.shell/project-generation.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ run_project_generation() {
140140
--project-version="$VERSION"
141141
--path=./
142142
--project-dir="$PROJECT_DIR"
143+
--no-feature
143144
--no-cache
144145
--skip-github-app
145146
)

.shell/test-add-dependency-command.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ run_project_generation() {
4747
--project-version="$VERSION"
4848
--path=./
4949
--project-dir="$PROJECT_DIR"
50+
--no-feature
5051
--no-cache
5152
--skip-github-app
5253
)

src/ar_infra/cli/command/init.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class InitCommandArgs:
4646
project_dir: str | None
4747
features: str | None
4848
no_features: str | None
49+
no_feature: bool
4950
no_cache: bool
5051
skip_github_app: bool
5152

@@ -71,22 +72,28 @@ def execute(self, args: InitCommandArgs) -> None:
7172
)
7273

7374
if is_interactive:
74-
self._execute_interactive(skip_github_app=args.skip_github_app)
75+
self._execute_interactive(
76+
skip_github_app=args.skip_github_app, skip_features=args.no_feature
77+
)
7578
else:
7679
self._execute_cli(args)
7780

78-
def _execute_interactive(self, *, skip_github_app: bool = False) -> None:
81+
def _execute_interactive(
82+
self, *, skip_github_app: bool = False, skip_features: bool = False
83+
) -> None:
7984
Banner.show(wait_for_enter=True)
8085
try:
81-
inputs = self.interactive_prompt.collect_inputs(skip_github_app=skip_github_app)
86+
inputs = self.interactive_prompt.collect_inputs(
87+
skip_github_app=skip_github_app, skip_features=skip_features
88+
)
8289

8390
self._execute_common(
8491
group_id=inputs["group_id"],
8592
artifact_id=inputs["artifact_id"],
8693
version=inputs["version"],
8794
destination=str(inputs["destination"]),
8895
project_dir_name=inputs["project_dir_name"],
89-
enabled_features=set(inputs["enabled_features"] or []),
96+
enabled_features=set(inputs.get("enabled_features") or []),
9097
template_url=AR_INFRA_TEMPLATE,
9198
use_template_cache=inputs["use_template_cache"],
9299
)
@@ -125,7 +132,19 @@ def _execute_cli(self, args: InitCommandArgs) -> None:
125132
assert args.project_dir is not None
126133

127134
try:
128-
enabled_features = self._parse_features(args.features, args.no_features)
135+
enabled_features = self._parse_features(
136+
args.features, args.no_features, no_feature=args.no_feature
137+
)
138+
139+
database_features = {"postgresql", "mysql"}
140+
selected_databases = enabled_features & database_features
141+
142+
if len(selected_databases) > 1:
143+
self._abort(
144+
"Only one database can be selected. "
145+
f"You have selected: {', '.join(sorted(selected_databases))}. "
146+
"Please choose either 'postgresql' or 'mysql', not both."
147+
)
129148

130149
destination_path = Path(args.path or ".").resolve()
131150
project_path = destination_path / args.project_dir
@@ -252,7 +271,12 @@ def _create_use_case() -> GenerateProjectUseCase:
252271
def _parse_features(
253272
features: str | None,
254273
no_features: str | None,
274+
*,
275+
no_feature: bool,
255276
) -> set[str]:
277+
if no_feature:
278+
return set()
279+
256280
all_features = {"postgresql", "mysql", "rabbitmq", "s3_bucket", "email"}
257281

258282
if features is not None:

src/ar_infra/cli/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def _show_help_and_exit(
6666
@click.option("--project-dir", type=str, help=PROJECT_DIR_OPTION_HELP)
6767
@click.option("--features", type=str, help=FEATURES_OPTION_HELP)
6868
@click.option("--disable-features", type=str, help=NO_FEATURES_OPTION_HELP)
69+
@click.option(
70+
"--no-feature", "no_feature", is_flag=True, help="Generate project without any features"
71+
)
6972
@click.option("--no-cache", "no_cache", is_flag=True, help=NO_CACHE_OPTION_HELP)
7073
@click.option(
7174
"--skip-github-app",
@@ -91,6 +94,7 @@ def init(
9194
features: str | None,
9295
disable_features: str | None,
9396
*,
97+
no_feature: bool,
9498
no_cache: bool,
9599
skip_github_app: bool,
96100
) -> None:
@@ -103,6 +107,7 @@ def init(
103107
project_dir=project_dir,
104108
features=features,
105109
no_features=disable_features,
110+
no_feature=no_feature,
106111
no_cache=no_cache,
107112
skip_github_app=skip_github_app,
108113
)

src/ar_infra/cli/prompt/interactive_prompt.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ def __init__(self) -> None:
2828
self.security_validator = PathSecurityValidator()
2929
self.github_app_handler = GitHubAppHandler()
3030

31-
def collect_inputs(self, *, skip_github_app: bool = False) -> dict[str, Any]:
31+
def collect_inputs(
32+
self, *, skip_github_app: bool = False, skip_features: bool = False
33+
) -> dict[str, Any]:
3234
while True:
33-
inputs = self._collect_all_prompts()
35+
inputs = self._collect_all_prompts(skip_features=skip_features)
3436

3537
if self._confirm_and_proceed(inputs):
3638
if not skip_github_app:
@@ -55,7 +57,7 @@ def collect_inputs(self, *, skip_github_app: bool = False) -> dict[str, Any]:
5557

5658
print("\n")
5759

58-
def _collect_all_prompts(self) -> dict[str, Any]:
60+
def _collect_all_prompts(self, *, skip_features: bool = False) -> dict[str, Any]:
5961
group_id = self._prompt_group_id()
6062
artifact_id = self._prompt_artifact_id()
6163
version = self._prompt_version()
@@ -77,7 +79,8 @@ def _collect_all_prompts(self) -> dict[str, Any]:
7779
print("\nOperation cancelled.\n")
7880
raise KeyboardInterrupt(OPERATION_CANCELLED_ERR_MESSAGE) from None
7981

80-
features = self._prompt_features()
82+
features = [] if skip_features else self._prompt_features()
83+
8184
use_cache = self._prompt_use_cache()
8285

8386
return {

src/ar_infra/cli/ui/help.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
from rich.table import Table
66
from rich.text import Text
77

8+
from src.ar_infra.cli.resources.documentation import (
9+
ADD_DEPENDENCY_PROJECT_PATH_HELP,
10+
ARTIFACT_OPTION_HELP,
11+
FEATURES_OPTION_HELP,
12+
GROUP_OPTION_HELP,
13+
NO_CACHE_OPTION_HELP,
14+
NO_FEATURES_OPTION_HELP,
15+
PATH_OPTION_HELP,
16+
PROJECT_DIR_OPTION_HELP,
17+
SKIP_COMMAND,
18+
VERSION_OPTION_HELP,
19+
)
820
from src.ar_infra.properties import AR_INFRA_TEMPLATE
921

1022

@@ -151,7 +163,7 @@ def show_init_command_body(console: Console) -> None:
151163
console.print("[bold yellow]COMMAND LINE MODE:[/bold yellow]")
152164
console.print(
153165
Syntax(
154-
"ar-infra init --group=com.example --artifact=myapp --project-version=1.0.0",
166+
"ar-infra init --group=com.example --artifact=myapp --no-feature",
155167
"bash",
156168
theme="monokai",
157169
background_color="default",
@@ -160,6 +172,44 @@ def show_init_command_body(console: Console) -> None:
160172
console.print()
161173

162174

175+
def show_init_options(console: Console) -> None:
176+
console.print("[bold yellow]INIT OPTIONS:[/bold yellow]")
177+
options_table = Table(show_header=False, box=None, padding=(0, 2))
178+
options_table.add_column(style="cyan bold", width=20)
179+
options_table.add_column()
180+
181+
options_table.add_row("--group", GROUP_OPTION_HELP.strip())
182+
options_table.add_row("--artifact", ARTIFACT_OPTION_HELP.strip())
183+
options_table.add_row("--project-version", VERSION_OPTION_HELP.strip())
184+
options_table.add_row("--path", PATH_OPTION_HELP.strip())
185+
options_table.add_row("--project-dir", PROJECT_DIR_OPTION_HELP.strip())
186+
options_table.add_row("--features", FEATURES_OPTION_HELP.strip())
187+
options_table.add_row("--disable-features", NO_FEATURES_OPTION_HELP.strip())
188+
options_table.add_row("--no-feature", "Generate project without any features")
189+
options_table.add_row("--no-cache", NO_CACHE_OPTION_HELP.strip())
190+
options_table.add_row("--skip-github-app", SKIP_COMMAND.strip())
191+
192+
console.print(options_table)
193+
console.print()
194+
195+
196+
def show_add_deps_options(console: Console) -> None:
197+
console.print("[bold yellow]ADD-DEPENDENCY OPTIONS:[/bold yellow]")
198+
options_table = Table(show_header=False, box=None, padding=(0, 2))
199+
options_table.add_column(style="cyan bold", width=20)
200+
options_table.add_column()
201+
202+
options_table.add_row(
203+
"DEPENDENCIES...", "One or more Gradle dependency strings to add (required)."
204+
)
205+
206+
options_table.add_row("--project-path", ADD_DEPENDENCY_PROJECT_PATH_HELP.strip())
207+
options_table.add_row("--help, -h", "Show this message and exit.")
208+
209+
console.print(options_table)
210+
console.print()
211+
212+
163213
def show_help() -> None:
164214
console = Console()
165215

@@ -173,7 +223,9 @@ def show_help() -> None:
173223
console.print(" ar-infra init [OPTIONS]")
174224

175225
show_add_deps_header(console)
226+
show_add_deps_options(console)
176227
show_init_command_body(console)
228+
show_init_options(console)
177229
show_init_command_example(console)
178230
show_add_deps_body(console)
179231
show_feature_list(console)

0 commit comments

Comments
 (0)