def init()

in solutions_builder/cli/cli.py [0:0]


def init(solution_path: Annotated[Optional[str], typer.Argument()] = "."):
  """
  Initialize sb.yaml for a solution folder.
  """
  components = None

  if os.path.isfile(solution_path + "/sb.yaml"):
    confirm(f"This will override the existing 'sb.yaml' in '{solution_path}'. "
            "Continue?", default=False)
    sb_yaml = read_yaml(f"{solution_path}/sb.yaml")
    components = sb_yaml.get("components", {})

  else:
    confirm(f"This will create a new 'sb.yaml' in '{solution_path}'. "
            "Continue?", default=True)

  template_path = get_package_dir() + "/helper_modules/init_sb_yaml"
  run_copy(template_path, solution_path, data={}, unsafe=True)

  # Restore components.
  if components:
    sb_yaml = read_yaml(f"{solution_path}/sb.yaml")
    sb_yaml["components"] = components
    write_yaml(f"{solution_path}/sb.yaml", sb_yaml)

  print_success("Complete.")