Skip to content

Commit

Permalink
add getFlag,loadResource cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Chadiii committed Apr 11, 2024
1 parent 7c567bf commit 32761a2
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 29 deletions.
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@ inputs:
list-flag:
description: 'list flag'
required: false

get-flag:
description: 'get flag'
required: false

load-resource:
description: 'load resource from resource loader'
required: false
# Define your outputs here.
outputs:
COMMAND_RESPONSE:
commandsResult:
description: 'result of the cli'

runs:
Expand Down
57 changes: 41 additions & 16 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/cliCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ export class Cli {
method === 'list'
? `${cliBin} ${resource} ${method} ${args}`
: `${cliBin} ${resource} ${method} ${args} --output-format json`
console.log(command)
const output = await this.exec(command, {})
if (output.stderr) {
return `error occured with command ${command}`
}
return JSON.stringify(output.stdout)
return output.stdout
} catch (err: any) {
return err.toString()
}
Expand Down
2 changes: 2 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const DELETE_CONFIGURATION = 'delete-configuration'
export const USE_CONFIGURATION = 'use-configuration'

export const LIST_FLAG = 'list-flag'
export const GET_FLAG = 'get-flag'
export const LOAD_RESOURCE = 'load-resource'
47 changes: 37 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
CREATE_CONFIGURATION,
DELETE_CONFIGURATION,
EDIT_CONFIGURATION,
GET_FLAG,
LIST_FLAG,
LOAD_RESOURCE,
USE_CONFIGURATION
} from './const'
/**
Expand All @@ -19,6 +21,7 @@ import {
*/

type CliRequest = {
commandId: string
method: string
resource: string
flags: string
Expand Down Expand Up @@ -58,6 +61,14 @@ const buildInputs = () => {
}
}

const getFlag = core.getMultilineInput(GET_FLAG)
if (core.getInput(GET_FLAG)) {
commandRequests = {
...commandRequests,
[GET_FLAG]: getFlag
}
}

const listFlag = core.getMultilineInput(LIST_FLAG)
if (core.getInput(LIST_FLAG)) {
commandRequests = {
Expand All @@ -66,6 +77,14 @@ const buildInputs = () => {
}
}

const loadResource = core.getMultilineInput(LOAD_RESOURCE)
if (core.getInput(LOAD_RESOURCE)) {
commandRequests = {
...commandRequests,
[LOAD_RESOURCE]: loadResource
}
}

return commandRequests
}

Expand All @@ -75,8 +94,13 @@ const buildCommands = (
var cliRequests: CliRequest[] = []
for (const [key, value] of Object.entries(commandRequests)) {
var args: string = ''
var commandId: string = ''
value?.map((f: string) => {
var f_ = f.replaceAll(' ', '').split(':')
if (f_[0] == 'commandId') {
commandId = f_[1]
return
}
args =
f_.length > 1
? args.concat(`--${f_[0]}=${f_[1]} `)
Expand All @@ -85,6 +109,7 @@ const buildCommands = (

const splitted = key.split('-')
cliRequests.push({
commandId,
method: splitted[0],
resource: splitted[1],
flags: args
Expand All @@ -101,9 +126,9 @@ export async function run(): Promise<void> {
//const internalFlagshipDir = '.flagship'

const internalConfigutations = `${internalFlagshipDir}/configurations`
var cliResponse: string[] = []
var cliResponse = {}

if (!fs.existsSync(internalFlagshipDir)) {
/* if (!fs.existsSync(internalFlagshipDir)) {
fs.mkdirSync(internalFlagshipDir)
}
Expand All @@ -113,10 +138,9 @@ export async function run(): Promise<void> {
fs.mkdirSync(internalConfigutations)
}
fs.chmodSync(`${internalConfigutations}`, '777')
fs.chmodSync(`${internalConfigutations}`, '777') */

if (!fs.existsSync(binaryDir)) {
console.log('download')
await CliDownloader(binaryDir)
}

Expand All @@ -125,12 +149,15 @@ export async function run(): Promise<void> {
const commandRequests = buildInputs()
const cliRequests = buildCommands(commandRequests)

cliRequests.map(async r => {
const resp = await cli.Resource(r.resource, r.method, r.flags)
console.log(resp)
cliResponse.push(resp)
})
core.setOutput('COMMAND_RESPONSE', cliResponse)
for (const r of cliRequests) {
const result = await cli.Resource(r.resource, r.method, r.flags)
cliResponse = {
...cliResponse,
[r.commandId]: result
}
}

core.setOutput('commandsResult', cliResponse)
} catch (err) {
console.log(err)
}
Expand Down

0 comments on commit 32761a2

Please sign in to comment.