-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto-suggest and execute command on error
- Loading branch information
Showing
8 changed files
with
121 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,57 @@ | ||
import consola from 'consola' | ||
import { runCommand } from 'citty' | ||
import type { Project } from '@shelve/types' | ||
import link from '../commands/link.ts' | ||
import login from '../commands/login.ts' | ||
import { createProject } from './projects.ts' | ||
|
||
export async function suggestCreateProject(name?: string): Promise<Project | null> { | ||
const accept = await consola.prompt('Do you want to create a project? (y/n)', { | ||
default: 'y', | ||
type: 'confirm', | ||
}) | ||
if (accept) { | ||
if (name) { | ||
return await createProject(name) | ||
} | ||
const projectName = await consola.prompt('Give your project a name', { | ||
placeholder: 'my-project' | ||
}) | ||
return await createProject(projectName) | ||
} | ||
return null | ||
} | ||
|
||
export async function suggestLinkProject(name: string): Promise<Project | null> { | ||
const linkProject = await consola.prompt('Do you want to link the project? (y/n)', { | ||
default: 'y', | ||
type: 'confirm', | ||
}) | ||
if (linkProject) { | ||
const res = await runCommand(link, {rawArgs: ['--name', name]}) as { result: Project } | ||
return res.result | ||
} | ||
return null | ||
} | ||
|
||
export async function suggestLinkProjects(): Promise<Project | null> { | ||
const linkProject = await consola.prompt('Do you want to link a project? (y/n)', { | ||
default: 'y', | ||
type: 'confirm', | ||
}) | ||
if (linkProject) { | ||
const res = await runCommand(link, {rawArgs: []}) as { result: Project } | ||
return res.result | ||
} | ||
return null | ||
} | ||
|
||
export async function suggestLogin(): Promise<void> { | ||
const accept = await consola.prompt('Do you want to login? (y/n)', { | ||
default: 'y', | ||
type: 'confirm', | ||
}) | ||
if (accept) { | ||
await runCommand(login, {rawArgs: []}) | ||
} | ||
} |