Skip to content
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

refactor: Add select all projects option #66

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions packages/globe_cli/lib/src/utils/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,7 @@ class GlobeApi {
)! as Map<String, Object?>;
final token = Token.fromJson(response);

final generateTokenPath = '/orgs/$orgId/api-tokens/${token.uuid}/generate';
logger.detail('API Request: GET $generateTokenPath');

// get token value
final tokenValue = _handleResponse(
await http.get(_buildUri(generateTokenPath), headers: headers),
)! as String;

return (id: token.uuid, value: tokenValue);
return (id: token.uuid, value: token.value!);
}

Future<List<Token>> listTokens({
Expand Down Expand Up @@ -696,13 +688,15 @@ class Token {
final String organizationUuid;
final DateTime expiresAt;
final List<String> cliTokenClaimProject;
final String? value;

const Token._({
required this.uuid,
required this.name,
required this.organizationUuid,
required this.expiresAt,
required this.cliTokenClaimProject,
required this.value,
});

factory Token.fromJson(Map<String, dynamic> json) {
Expand All @@ -713,6 +707,7 @@ class Token {
'organizationUuid': final String organizationUuid,
'expiresAt': final String expiresAt,
'projects': final List<dynamic> projects,
'value': final String? value,
} =>
Token._(
uuid: uuid,
Expand All @@ -722,6 +717,7 @@ class Token {
cliTokenClaimProject: projects
.map((e) => (e as Map)['projectUuid'].toString())
.toList(),
value: value,
),
_ => throw const FormatException('Token'),
};
Expand Down
10 changes: 9 additions & 1 deletion packages/globe_cli/lib/src/utils/prompts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,20 @@ Future<List<Project>> selectProjects(
final projectsBySlug = projects
.fold<Map<String, Project>>({}, (prev, curr) => prev..[curr.slug] = curr);

final projectChoices = projectsBySlug.keys.toList();
projectChoices.insert(0, 'All projects');

/// Ask user to choose zero or more options.
final selections = logger.chooseAny(
'❓ $question',
choices: projectsBySlug.keys.toList(),
choices: projectChoices,
);

if (selections.contains('All projects')) {
logger.detail('All projects selected.');
return projects;
}

if (selections.isEmpty) {
logger.detail(
'No projects selected, you need to select atleast one project.',
Expand Down
Loading