forked from UBAutograding/leviathan
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from makeopensource/cli-docker-controls
Implemented Api Cli
- Loading branch information
Showing
10 changed files
with
716 additions
and
189 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,24 +1,87 @@ | ||
#!/usr/bin/env node | ||
|
||
import {Command} from 'commander'; | ||
import {CoursesApi, DockerApi} from 'leviathan-client' | ||
import {DockerApi} from 'leviathan-client'; | ||
import inquirer from 'inquirer'; | ||
|
||
const program = new Command(); | ||
|
||
program | ||
.version('1.0.0') | ||
.description('A simple TypeScript CLI application') | ||
.option('-n, --name <name>', 'Your name') | ||
.option('-g, --greeting <greeting>', 'Custom greeting', 'Hello') | ||
.action((options) => { | ||
const name = options.name || 'World'; | ||
console.log(`${options.greeting}, ${name}!`); | ||
}); | ||
.description('A CLI to interact with the Leviathan API'); | ||
|
||
program.parse(process.argv); | ||
const baseUrl = "http://localhost:9221" | ||
|
||
const courses = new DockerApi(undefined ,"http://localhost:9221"); | ||
// const coursesApi = new CoursesApi(undefined, "http://localhost:9221"); | ||
const dockerApi = new DockerApi(undefined, baseUrl); | ||
const dockerEndpoints = { | ||
"Get Container info": async () => { | ||
const {containerId} = await inquirer.prompt([ | ||
{type: 'input', name: 'containerId', message: 'Enter the container ID:'} | ||
]); | ||
|
||
courses.dockerContainerIdDelete(94882).then(value => { | ||
console.log(value) | ||
}) | ||
const result = await dockerApi.dockerContainerIdGet(containerId as string); | ||
console.log(`Status: ${result.status}, message: ${result.statusText}`); | ||
}, | ||
'Delete Container': async () => { | ||
const {containerId} = await inquirer.prompt([ | ||
{type: 'input', name: 'containerId', message: 'Enter the container ID:'} | ||
]); | ||
|
||
const result = await dockerApi.dockerContainerIdDelete(parseInt(containerId)); | ||
console.log(`Status: ${result.status}, message: ${result.statusText}`); | ||
}, | ||
'Start Docker Container': async () => { | ||
const {containerId} = await inquirer.prompt([ | ||
{type: 'input', name: 'containerId', message: 'Enter the container ID:'} | ||
]); | ||
const result = await dockerApi.dockerContainerIdStartGet(parseInt(containerId)); | ||
console.log(`Status: ${result.status}, message: ${result.statusText}`); | ||
}, | ||
'Stop Docker Container': async () => { | ||
const {containerId} = await inquirer.prompt([ | ||
{type: 'input', name: 'containerId', message: 'Enter the container ID:'} | ||
]); | ||
const result = await dockerApi.dockerContainerIdStopGet(parseInt(containerId)); | ||
console.log(`Status: ${result.status}, message: ${result.statusText}`); | ||
}, | ||
// todo | ||
// 'Create Docker image': async () => { | ||
// const file = fs.readFileSync('../ex-Dockerfile', 'utf8'); | ||
// // const result = await dockerApi.dockerImagesCreatePost(file ,"test:latest"); | ||
// // console.log(JSON.stringify(result, null, 2)); | ||
// }, | ||
}; | ||
|
||
async function main() { | ||
while (true) { | ||
const {action} = await inquirer.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'action', | ||
message: 'Choose an endpoint to call:', | ||
choices: [...Object.keys(dockerEndpoints), 'Exit'] | ||
} | ||
]); | ||
|
||
if (action === 'Exit') { | ||
console.log('Goodbye!'); | ||
break; | ||
} | ||
|
||
try { | ||
const act = action as string | ||
// @ts-ignore | ||
await dockerEndpoints[act](); | ||
} catch (error) { | ||
// @ts-ignore | ||
console.error('An error occurred:', error.message); | ||
} | ||
|
||
console.log('\n'); | ||
} | ||
} | ||
|
||
program.action(main); | ||
|
||
program.parse(process.argv); |
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
2 changes: 1 addition & 1 deletion
2
internal/messagestore/message_store.go → internal/message-store/message_store.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package messagestore | ||
package message_store | ||
|
||
import ( | ||
"github.com/ThreeDotsLabs/watermill/message" | ||
|
Oops, something went wrong.