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

Tas 11/ Add command alias #158

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ The Tower CLI is a platform binary executable created by a native compilation fr
3. Create the native client:

```bash
./gradlew nativeImage
./gradlew nativeCompile
```

4. Run `tw`:

```bash
./build/graal/tw
./build/native/nativeCompile/tw
```

## Using non-binary development versions
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ dependencies {
implementation 'ch.qos.logback:logback-core:1.2.6'
implementation 'ch.qos.logback:logback-classic:1.2.6'
implementation 'io.seqera:tower-java-sdk:1.1.0'
implementation 'info.picocli:picocli:4.6.1'
annotationProcessor 'info.picocli:picocli-codegen:4.6.1'
implementation 'info.picocli:picocli:4.6.2'
annotationProcessor 'info.picocli:picocli-codegen:4.6.2'

testImplementation 'org.mock-server:mockserver-client-java:5.11.2'
testImplementation 'org.mock-server:mockserver-netty:5.11.2'
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/seqera/tower/cli/commands/ActionsCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@CommandLine.Command(
name = "actions",
aliases = {"action"},
description = "Manage actions.",
subcommands = {
ListCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

@CommandLine.Command(
name = "collaborators",
aliases = {"collab"},
description = "Manage organization collaborators.",
subcommands = {
ListCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

@Command(
name = "compute-envs",
aliases = {"ce"},
description = "Manage workspace compute environments.",
subcommands = {
AddCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@Command(
name = "credentials",
aliases = {"cred"},
description = "Manage workspace credentials.",
subcommands = {
AddCmd.class,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/seqera/tower/cli/commands/MembersCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@CommandLine.Command(
name = "members",
aliases = {"member"},
description = "Manage organization members.",
subcommands = {
ListCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@CommandLine.Command(
name = "organizations",
aliases = {"org"},
description = "Manage organizations.",
subcommands = {
ListCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@CommandLine.Command(
name = "participants",
aliases = {"part"},
description = "Manage workspace participants.",
subcommands = {
ListCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

@Command(
name = "pipelines",
aliases = {"pipe"},
description = "Manage workspace pipeline launchpad.",
subcommands = {
ListCmd.class,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/seqera/tower/cli/commands/RunsCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@CommandLine.Command(
name = "runs",
aliases = {"run"},
description = "Manage workspace pipeline runs.",
subcommands = {
ViewCmd.class,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/seqera/tower/cli/commands/TeamsCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@CommandLine.Command(
name = "teams",
aliases = {"team"},
description = "Manage organization teams.",
subcommands = {
ListCmd.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

@CommandLine.Command(
name = "workspaces",
aliases = {"wsp"},
description = "Manage workspaces.",
subcommands = {
ListCmd.class,
Expand Down
96 changes: 96 additions & 0 deletions src/test/java/io/seqera/tower/cli/actions/ActionsCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,102 @@ void testView(OutputType format, MockServerClient mock) throws JsonProcessingExc
" }", Action.class)));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testViewAlias(OutputType format, MockServerClient mock) throws JsonProcessingException {
mock.reset();

mock.when(
request().withMethod("GET").withPath("/actions"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("actions/actions_list")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/actions/57byWxhmUDLLWIF4J97XEP"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("actions/action_view")).withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(format, mock, "action", "view", "-n", "hello");
assertOutput(format, out, new ActionsView(parseJson("{\n" +
" \"id\": \"57byWxhmUDLLWIF4J97XEP\",\n" +
" \"launch\": {\n" +
" \"id\": \"3htPtgK2KufwvQcovOko\",\n" +
" \"computeEnv\": {\n" +
" \"id\": \"1NcvsrdHeaKsrpgQ85NYpe\",\n" +
" \"name\": \"deleted-774901692352490\",\n" +
" \"description\": null,\n" +
" \"platform\": \"slurm-platform\",\n" +
" \"config\": {\n" +
" \"hostName\": \"slurm.seqera.io\",\n" +
" \"workDir\": \"/home/ubuntu/nf-work\",\n" +
" \"userName\": \"ubuntu\",\n" +
" \"preRunScript\": null,\n" +
" \"postRunScript\": null,\n" +
" \"headQueue\": \"long\",\n" +
" \"launchDir\": \"/home/ubuntu/nf-work\",\n" +
" \"headJobOptions\": null,\n" +
" \"computeQueue\": null,\n" +
" \"port\": null,\n" +
" \"maxQueueSize\": null,\n" +
" \"discriminator\": \"slurm-platform\"\n" +
" },\n" +
" \"dateCreated\": \"2021-06-18T08:58:21Z\",\n" +
" \"lastUpdated\": \"2021-06-18T08:58:21Z\",\n" +
" \"lastUsed\": \"2021-06-18T10:22:31Z\",\n" +
" \"deleted\": true,\n" +
" \"status\": \"AVAILABLE\",\n" +
" \"message\": null,\n" +
" \"primary\": null,\n" +
" \"credentialsId\": \"5KmzwVT34sT8ItofmP5S\"\n" +
" },\n" +
" \"pipeline\": \"https://github.com/pditommaso/hello\",\n" +
" \"workDir\": \"/home/ubuntu/nf-work\",\n" +
" \"revision\": null,\n" +
" \"configText\": null,\n" +
" \"paramsText\": null,\n" +
" \"preRunScript\": null,\n" +
" \"postRunScript\": null,\n" +
" \"mainScript\": null,\n" +
" \"entryName\": null,\n" +
" \"schemaName\": null,\n" +
" \"resume\": false,\n" +
" \"pullLatest\": false,\n" +
" \"stubRun\": false,\n" +
" \"sessionId\": null,\n" +
" \"configProfiles\": null,\n" +
" \"dateCreated\": \"2021-06-18T10:10:05Z\",\n" +
" \"lastUpdated\": \"2021-06-18T10:10:05Z\"\n" +
" },\n" +
" \"name\": \"hello\",\n" +
" \"hookId\": \"303166158\",\n" +
" \"hookUrl\": \"https://api.github.com/repos/pditommaso/hello/hooks/303166158\",\n" +
" \"message\": null,\n" +
" \"deleted\": null,\n" +
" \"source\": \"github\",\n" +
" \"status\": \"ACTIVE\",\n" +
" \"config\": {\n" +
" \"events\": [\n" +
" \"push\"\n" +
" ],\n" +
" \"discriminator\": \"github\"\n" +
" },\n" +
" \"event\": {\n" +
" \"ref\": \"refs/heads/master\",\n" +
" \"commitId\": \"af8d93083a36552914929a959f7576f62996032e\",\n" +
" \"commitMessage\": \"Update README.md\",\n" +
" \"pusherName\": \"pditommaso\",\n" +
" \"pusherEmail\": \"paolo.ditommaso@gmail.com\",\n" +
" \"timestamp\": \"2021-06-18T12:10:32+02:00\",\n" +
" \"discriminator\": \"github\"\n" +
" },\n" +
" \"lastSeen\": \"2021-06-18T10:10:33Z\",\n" +
" \"dateCreated\": \"2021-06-18T10:10:05Z\",\n" +
" \"lastUpdated\": \"2021-06-18T10:10:33Z\"\n" +
" }", Action.class)));
}

@Test
void testViewNoActionFound(MockServerClient mock) {
mock.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,50 @@ void testListCollaborators(OutputType format, MockServerClient mock) throws Json
" }", MemberDbDto.class)
)));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testListCollaboratorsAlias(OutputType format, MockServerClient mock) throws JsonProcessingException {
mock.when(
request().withMethod("GET").withPath("/user"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("user")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("workspaces/workspaces_list")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/orgs/27736513644467/collaborators")
.withQueryStringParameter("max", "100")
.withQueryStringParameter("offset", "0"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("collaborators/collaborators_list")).withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(format, mock, "collab", "list", "-o", "27736513644467");
assertOutput(format, out, new CollaboratorsList(27736513644467L, Arrays.asList(
parseJson(" {\n" +
" \"memberId\": 175703974560466,\n" +
" \"userName\": \"jfernandez74\",\n" +
" \"email\": \"jfernandez74@gmail.com\",\n" +
" \"firstName\": null,\n" +
" \"lastName\": null,\n" +
" \"avatar\": \"https://www.gravatar.com/avatar/7d3c1ee212a3465233e161b451fb4d05?d=404\",\n" +
" \"role\" : \"collaborator\"" +
" }", MemberDbDto.class),
parseJson("{\n" +
" \"memberId\": 255080245994226,\n" +
" \"userName\": \"julio\",\n" +
" \"email\": \"julio@seqera.io\",\n" +
" \"firstName\": null,\n" +
" \"lastName\": null,\n" +
" \"avatar\": \"https://www.gravatar.com/avatar/72918a9f674eaa696729917bec58760b?d=404\",\n" +
" \"role\" : \"collaborator\"" +
" }", MemberDbDto.class)
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ void testDelete(OutputType format, MockServerClient mock) {
assertOutput(format, out, new ComputeEnvDeleted("vYOK4vn7spw7bHHWBDXZ2", USER_WORKSPACE_NAME));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testDeleteAlias(OutputType format, MockServerClient mock) {
mock.when(
request().withMethod("DELETE").withPath("/compute-envs/vYOK4vn7spw7bHHWBDXZ2"), exactly(1)
).respond(
response().withStatusCode(204)
);

ExecOut out = exec(format, mock, "ce", "delete", "-i", "vYOK4vn7spw7bHHWBDXZ2");
assertOutput(format, out, new ComputeEnvDeleted("vYOK4vn7spw7bHHWBDXZ2", USER_WORKSPACE_NAME));
}

@Test
void testDeleteInvalidAuth(MockServerClient mock) {
mock.when(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ void testDelete(OutputType format, MockServerClient mock) {
assertOutput(format, out, new CredentialsDeleted("1cz5A8cuBkB5iJliCwJCFU", USER_WORKSPACE_NAME));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testDeleteAlias(OutputType format, MockServerClient mock) {
mock.when(
request().withMethod("DELETE").withPath("/credentials/1cz5A8cuBkB5iJliCwJCFU"), exactly(1)
).respond(
response().withStatusCode(204)
);

ExecOut out = exec(format, mock, "cred", "delete", "-i", "1cz5A8cuBkB5iJliCwJCFU");
assertOutput(format, out, new CredentialsDeleted("1cz5A8cuBkB5iJliCwJCFU", USER_WORKSPACE_NAME));
}

@Test
void testDeleteNotFound(MockServerClient mock) {
mock.when(
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/io/seqera/tower/cli/members/MembersCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,50 @@ void testList(OutputType format, MockServerClient mock) throws JsonProcessingExc
)));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testListAlias(OutputType format, MockServerClient mock) throws JsonProcessingException {
mock.when(
request().withMethod("GET").withPath("/user"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("user")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("workspaces/workspaces_list")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/orgs/27736513644467/members"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("members/members_list")).withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(format, mock, "member", "list", "-o", "organization1");
assertOutput(format, out, new MembersList("organization1", Arrays.asList(
parseJson(" {\n" +
" \"memberId\": 175703974560466,\n" +
" \"userName\": \"jfernandez74\",\n" +
" \"email\": \"jfernandez74@gmail.com\",\n" +
" \"firstName\": null,\n" +
" \"lastName\": null,\n" +
" \"avatar\": \"https://www.gravatar.com/avatar/7d3c1ee212a3465233e161b451fb4d05?d=404\",\n" +
" \"role\": \"owner\"\n" +
" }", MemberDbDto.class),
parseJson("{\n" +
" \"memberId\": 255080245994226,\n" +
" \"userName\": \"julio\",\n" +
" \"email\": \"julio@seqera.io\",\n" +
" \"firstName\": null,\n" +
" \"lastName\": null,\n" +
" \"avatar\": \"https://www.gravatar.com/avatar/72918a9f674eaa696729917bec58760b?d=404\",\n" +
" \"role\": \"member\"\n" +
" }", MemberDbDto.class)
)));
}

@Test
void testListWithOffset(MockServerClient mock) throws JsonProcessingException {
mock.when(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,39 @@ void testList(OutputType format, MockServerClient mock) throws JsonProcessingExc
)));
}

@ParameterizedTest
@EnumSource(OutputType.class)
void testListAlias(OutputType format, MockServerClient mock) throws JsonProcessingException {
mock.when(
request().withMethod("GET").withPath("/user"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("user")).withContentType(MediaType.APPLICATION_JSON)
);

mock.when(
request().withMethod("GET").withPath("/user/1264/workspaces"), exactly(1)
).respond(
response().withStatusCode(200).withBody(loadResource("workspaces/workspaces_list")).withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(format, mock, "org", "list");
assertOutput(format, out, new OrganizationsList("jordi", Arrays.asList(parseJson(" {\n" +
" \"orgId\": 27736513644467,\n" +
" \"orgName\": \"organization1\",\n" +
" \"orgLogoUrl\": null,\n" +
" \"workspaceId\": null,\n" +
" \"workspaceName\": null\n" +
" }", OrgAndWorkspaceDbDto.class),
parseJson(" {\n" +
" \"orgId\": 37736513644467,\n" +
" \"orgName\": \"organization2\",\n" +
" \"orgLogoUrl\": null,\n" +
" \"workspaceId\": null,\n" +
" \"workspaceName\": null\n" +
" }", OrgAndWorkspaceDbDto.class)
)));
}

@Test
void testListEmpty(MockServerClient mock) {
mock.when(
Expand Down
Loading