Skip to content

Commit

Permalink
wip: Enhance CLI functionalities #188
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Oct 20, 2020
1 parent 413ac56 commit 3880f09
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions kargo.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ async function apply () {
// Compute the difference
let delta = diffConfig()
if (!delta) return
console.log(delta)
// Apply the difference on labels
let labels = _.get(delta, 'labels', undefined)
console.log(labels)
_.forEach(_.toPairs(labels), node => {
let command = './scripts/update-labels ' + node[0] + ' '
let command = './scripts/update-labels.sh ' + node[0] + ' '
if (node[1].length > 2 ) {
console.log('remove labels ' + node[1] + ' on node ' + node[0])
command += '""'
Expand Down Expand Up @@ -288,21 +290,32 @@ function pull () {

function use (workspace) {
// TODO check states
// Check whether the specified path exists
if (!fs.existsSync(workspace)) {
log('The workspsace \'' + workspace + '\' does not exist', 'error')
log('The path \'' + workspace + '\' does not exist', 'error')
return
}
// Check whether the path is a directory
if (!fs.lstatSync(workspace).isDirectory()) {
log('The path \'' + workspace + '\' must be a directory', 'error')
return
}
// Check wether it contains a config.json file
let workspaceConfigFile = path.join(workspace, workspaceConfigFileName)
if (!fs.existsSync(workspaceConfigFile)) {
log('The workspsace \'' + workspace + '\' does not contains any \'config.json\' file', 'error')
log('The directory \'' + workspace + '\' does not contains any \'config.json\' file', 'error')
return
}
// Ensure the runtime structure exists
shell.mkdir('-p', runtimeDir)
shell.mkdir('-p', runtimeDeployDir)
shell.mkdir('-p', runtimeConfigsDir)
shell.mkdir('-p', runtimeScriptsDir)
// Configure the states
_.set(states, 'workspace', { name: path.basename(workspace), path: workspace })
states = {
'workspace': { 'name': path.basename(workspace), 'path': workspace },
'config': { environment: {}, labels: {}, stacks: {} }
}
// Save the states
if (writeStates()) {
log('Switched to \'' + states.workspace.name + '\'')
Expand Down

0 comments on commit 3880f09

Please sign in to comment.