Skip to content

Commit

Permalink
chore: Pass org if already selected (#125)
Browse files Browse the repository at this point in the history
* pass org if already selected

* _
  • Loading branch information
codekeyz authored Dec 27, 2024
1 parent f392a68 commit 56a5c79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 33 deletions.
3 changes: 2 additions & 1 deletion packages/globe_cli/lib/src/package_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

const name = 'globe_cli';
const version = '0.0.14-dev.0+1';
const description = 'The global deployment platform for Dart & Flutter applications.';
const description =
'The global deployment platform for Dart & Flutter applications.';
const executable = 'globe';
8 changes: 4 additions & 4 deletions packages/globe_cli/lib/src/utils/prompts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import 'scope.dart';
Future<ScopeMetadata> linkProject({
required Logger logger,
required GlobeApi api,
Organization? org,
}) async {
try {
final organization = await selectOrganization(
logger: logger,
api: api,
);
final organization =
org ?? await selectOrganization(logger: logger, api: api);

final project = await selectProject(
organization,
Expand Down Expand Up @@ -111,6 +110,7 @@ Future<Project> selectProject(
String message = '❓ Please select a project you want to link:',
}) async {
logger.detail('Fetching organization projects');

final projects = await api.getProjects(org: organization.id);
logger.detail('Found ${projects.length} projects');

Expand Down
59 changes: 31 additions & 28 deletions packages/globe_cli/lib/src/utils/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,40 @@ class GlobeScope {
}) async {
if (hasScope()) return current!;

final selectOrg = await selectOrganization(logger: logger, api: api);
const linkNewProjectSymbol = '__LINK_NEW_PROJECT';

final scopes = workspace.where((p) => p.orgId == selectOrg.id);
var selectedProject = linkNewProjectSymbol;

if (scopes.length > 1) {
selectedProject = logger.chooseOne(
'🔺 Select project:',
choices: [
...scopes.map((o) => o.projectId),
if (canLinkNew) linkNewProjectSymbol,
],
display: (choice) {
if (choice == linkNewProjectSymbol) {
return lightYellow.wrap('link new project +')!;
}
return scopes.firstWhere((o) => o.projectId == choice).projectSlug;
},
);
} else if (scopes.length == 1) {
return setScope(scopes.first);
}
final selectedOrg = await selectOrganization(logger: logger, api: api);

if (workspace.isNotEmpty) {
const linkNewProjectSymbol = '__LINK_NEW_PROJECT';

final scopes = workspace.where((p) => p.orgId == selectedOrg.id);
var selectedProject = linkNewProjectSymbol;

if (scopes.length > 1) {
selectedProject = logger.chooseOne(
'🔺 Select project:',
choices: [
...scopes.map((o) => o.projectId),
if (canLinkNew) linkNewProjectSymbol,
],
display: (choice) {
if (choice == linkNewProjectSymbol) {
return lightYellow.wrap('link new project +')!;
}
return scopes.firstWhere((o) => o.projectId == choice).projectSlug;
},
);
} else if (scopes.length == 1) {
return setScope(scopes.first);
}

if (selectedProject != linkNewProjectSymbol) {
return setScope(
scopes.firstWhere((scope) => scope.projectId == selectedProject),
);
if (selectedProject != linkNewProjectSymbol) {
return setScope(
scopes.firstWhere((scope) => scope.projectId == selectedProject),
);
}
}

return linkProject(logger: logger, api: api);
return linkProject(logger: logger, api: api, org: selectedOrg);
}

Future<Organization> _findOrg() async {
Expand Down

0 comments on commit 56a5c79

Please sign in to comment.