Skip to content

Commit

Permalink
Extract reusable pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
sultaniman committed Mar 21, 2024
1 parent a399f23 commit 8e967b8
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions dlt/common/cli/runner/inquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,12 @@ def maybe_ask(self) -> t.Tuple[dlt.Pipeline, t.Union[DltResource, DltSource]]:
"""
# save first pipeline and source
pipeline_name, _ = next(iter(self.pipelines.items()))
source_name, _ = next(iter(self.pipelines.items()))
source_name, _ = next(iter(self.sources.items()))
if len(self.pipelines) > 1:
message, options, values = make_select_options("pipeline", self.pipelines)
choice = fmt.prompt(message, options, default="n")
if choice == "n":
raise FriendlyExit()
else:
pipeline_name = values[int(choice)]
pipeline_name = self.ask_for_pipeline()

if len(self.sources) > 1:
message, options, values = make_select_options("resource or source", self.sources)
choice = fmt.prompt(message, options, default="n")
if choice == "n":
raise FriendlyExit()
else:
source_name = values[int(choice)]
source_name = self.ask_for_source()

pipeline = self.pipelines[pipeline_name]
resource = self.sources[source_name]
Expand All @@ -77,6 +67,27 @@ def maybe_ask(self) -> t.Tuple[dlt.Pipeline, t.Union[DltResource, DltSource]]:
fmt.echo(f"{label}: " + fmt.style(source_name, fg="blue", underline=True))
return pipeline, self.sources[source_name]

def ask_for_pipeline(self) -> str:
if len(self.pipelines) > 1:
message, options, values = make_select_options("pipeline", self.pipelines)

choice = fmt.prompt(message, options, default="n")
if choice == "n":
raise FriendlyExit()

pipeline_name = values[int(choice)]
return pipeline_name

def ask_for_source(self) -> str:
message, options, values = make_select_options("resource or source", self.sources)

choice = fmt.prompt(message, options, default="n")
if choice == "n":
raise FriendlyExit()

source_name = values[int(choice)]
return source_name

def preflight_checks(self) -> None:
if self.params.current_dir != self.params.pipeline_workdir:
fmt.warning(
Expand Down

0 comments on commit 8e967b8

Please sign in to comment.