-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(start): add --interactive flag for start command
- Loading branch information
1 parent
012ea18
commit ef73332
Showing
8 changed files
with
126 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './input-time-entry-description' | ||
export * from './input-token' | ||
export * from './select-project' | ||
export * from './select-workspace' | ||
|
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,11 @@ | ||
import {input} from "@inquirer/prompts"; | ||
|
||
import {messages} from "../../core"; | ||
|
||
export function inputTimeEntryDescription(message = messages.forms.description.message) { | ||
return input({ | ||
default: messages.forms.description.default, | ||
message, | ||
validate: Boolean | ||
}); | ||
} |
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,7 @@ | ||
import {input} from "@inquirer/prompts"; | ||
|
||
import {messages} from "../../core"; | ||
|
||
export function inputToken() { | ||
return input({message: messages.forms.token}) | ||
} |
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,29 @@ | ||
import {select} from "@inquirer/prompts"; | ||
|
||
import {messages} from "../../core"; | ||
import {UserInfo} from "../data-sources"; | ||
|
||
const sortByName = (a: { name: string }, b: { name: string }) => | ||
a.name > b.name | ||
? 1 | ||
: a.name < b.name | ||
? -1 | ||
: 0 | ||
export async function selectProject({clients, projects}: UserInfo, message = messages.forms.project) { | ||
const clientMap = new Map(clients.map(client => [client.id, client])) | ||
const choices = projects | ||
.filter(({active}) => active) | ||
.sort(sortByName) | ||
.map(project => ({ | ||
name: `${project.name} (${clientMap.get(project.client_id)?.name || 'No client'})`, | ||
value: project.id | ||
})) | ||
const defaultProjectId = await select({ | ||
choices, | ||
message, | ||
}); | ||
return { | ||
id: defaultProjectId, | ||
name: choices.find(({value}) => value === defaultProjectId)?.name | ||
} | ||
} |
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,29 @@ | ||
/* eslint-disable camelcase */ | ||
import {select} from "@inquirer/prompts"; | ||
|
||
import {messages} from "../../core"; | ||
import {UserInfo} from "../data-sources"; | ||
|
||
const sortByName = (a: { name: string }, b: { name: string }) => | ||
a.name > b.name | ||
? 1 | ||
: a.name < b.name | ||
? -1 | ||
: 0 | ||
|
||
export async function selectWorkspace({default_workspace_id, workspaces}: UserInfo) { | ||
workspaces.sort(sortByName) | ||
const defaultWorkspace = workspaces.find(({id}) => id === default_workspace_id)! | ||
const choices = [defaultWorkspace, ...workspaces.filter(({id}) => id !== default_workspace_id)].map(workspace => ({ | ||
name: workspace.name, | ||
value: workspace.id | ||
})) | ||
const defaultWorkspaceId = await select({ | ||
choices, | ||
message: messages.forms.workspace, | ||
}); | ||
return { | ||
id: defaultWorkspaceId, | ||
name: choices.find(({value}) => value === defaultWorkspaceId)?.name | ||
} | ||
} |