Repository navigation
feat(cli): add projects setup command
#4356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { boolean, CLIError, positional, string } from "@superset/cli-framework"; | ||
| import { command } from "../../../lib/command"; | ||
| import { requireHostTarget, resolveHostTarget } from "../../../lib/host-target"; | ||
|
|
||
| export default command({ | ||
| description: | ||
| "Adopt an existing project on a host (clone its repo or import a folder)", | ||
| args: [positional("id").required().desc("Project UUID to adopt")], | ||
| options: { | ||
| host: string().desc("Target host machineId"), | ||
| local: boolean().desc("Target this machine"), | ||
| parentDir: string().desc( | ||
| "Parent directory to clone the project's repo into (clone mode)", | ||
| ), | ||
| import: string().desc( | ||
| "Existing local repo path on the target host (import mode)", | ||
| ), | ||
| allowRelocate: boolean().desc( | ||
| "Permit re-importing at a different path if the project is already set up here", | ||
| ), | ||
| }, | ||
| run: async ({ ctx, args, options }) => { | ||
| const projectId = args.id as string; | ||
| const organizationId = ctx.config.organizationId; | ||
| if (!organizationId) { | ||
| throw new CLIError("No active organization", "Run: superset auth login"); | ||
| } | ||
|
|
||
| if (Boolean(options.parentDir) === Boolean(options.import)) { | ||
| throw new CLIError( | ||
| "Specify exactly one of --parent-dir or --import", | ||
| "Use --parent-dir <path> to clone, or --import <path> to register an existing folder", | ||
| ); | ||
| } | ||
| if (options.allowRelocate && !options.import) { | ||
| throw new CLIError( | ||
| "--allow-relocate only applies to --import", | ||
| "Drop --allow-relocate, or switch to --import <path>", | ||
| ); | ||
| } | ||
|
|
||
| const hostId = requireHostTarget({ | ||
| host: options.host ?? undefined, | ||
| local: options.local ?? undefined, | ||
| }); | ||
|
|
||
| const target = resolveHostTarget({ | ||
| requestedHostId: hostId, | ||
| organizationId, | ||
| userJwt: ctx.bearer, | ||
| }); | ||
|
|
||
| const mode = options.parentDir | ||
| ? { | ||
| kind: "clone" as const, | ||
| parentDir: options.parentDir, | ||
| } | ||
| : { | ||
| kind: "import" as const, | ||
| repoPath: options.import as string, | ||
| allowRelocate: options.allowRelocate ?? false, | ||
| }; | ||
|
|
||
| const result = await target.client.project.setup.mutate({ | ||
| projectId, | ||
| mode, | ||
| }); | ||
|
|
||
| return { | ||
| data: result, | ||
| message: `Set up project ${projectId} on host ${target.hostId}`, | ||
| }; | ||
| }, | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boolean(undefined) === Boolean(undefined)istrue, so a user who omits both flags sees "Specify exactly one of --parent-dir or --import" — a message that reads as if they supplied both rather than neither. The same pattern exists increate/command.ts, but here the lack of a--cloneanalogue makes the two-flag surface smaller and the "neither" case more likely to be hit accidentally. A disambiguated check (or a separateelse ifbranch) would make the error clearer to users in the omit-both path.Prompt To Fix With AI