Skip to content

Commit

Permalink
feat(package): create package subcommand
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
`xst install` is now  `xst package install` to prepare for
`xst package list` and other package related subcommands.
This is to avoid breaking changes in the near future when package list
is added  as `xst list` is already taken.

closes #34
  • Loading branch information
line-o committed Dec 14, 2022
1 parent 7a78d1d commit a079442
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
1 change: 1 addition & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const parser = yargs(hideBin(process.argv))
.completion('completion', false)
.command(commands)
.demandCommand(1)
// .recommendCommands()
.strict(false)
.fail(false)

Expand Down
4 changes: 2 additions & 2 deletions commands/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as exec from './exec.js'
import * as install from './install.js'
import * as pkg from './package/index.js'
import * as list from './list.js'
import * as upload from './upload.js'
import * as rm from './rm.js'
import * as get from './get.js'

export const commands = [
exec,
install,
pkg,
list,
upload,
rm,
Expand Down
12 changes: 12 additions & 0 deletions commands/package/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as install from './install.js'

export const command = ['package <command>', 'pkg']
export const describe = 'do something with packages'
export async function handler (argv) {
if (argv.help) {
return 0
}
}
export const builder = function (yargs) {
return yargs.command([install]).recommendCommands()
}
File renamed without changes.
10 changes: 8 additions & 2 deletions spec/fixtures/.xstrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
"basic_auth": {
"user": "admin",
"pass": ""
}
},
"rejectUnauthorized": false,
"host": "localhost",
"port": 8443,
"secure": true
},
"extensionsort": true
"extensionsort": true,
"color": true,
"insert-final-newline": true
}
22 changes: 11 additions & 11 deletions spec/tests/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ async function noTestApp (t) {
}

test('shows help', async function (t) {
const { stderr, stdout } = await run('xst', ['install', '--help'])
const { stderr, stdout } = await run('xst', ['package', 'install', '--help'])

if (stderr) { return t.fail(stderr) }
t.ok(stdout, 'got output')
const firstLine = stdout.split('\n')[0]
t.equal(firstLine, 'xst install [options] <packages..>', firstLine)
t.equal(firstLine, 'xst package install [options] <packages..>', firstLine)
})

test('single valid package', async function (t) {
t.test('installs on first run', async function (st) {
const { stderr, stdout } = await run('xst', ['install', 'spec/fixtures/test-app.xar'], asAdmin)
const { stderr, stdout } = await run('xst', ['package', 'install', 'spec/fixtures/test-app.xar'], asAdmin)
if (stderr) {
st.fail(stderr)
st.end()
Expand All @@ -47,7 +47,7 @@ test('single valid package', async function (t) {
})

t.test('updates on second run', async function (st) {
const { stderr, stdout } = await run('xst', ['install', 'spec/fixtures/test-app.xar'], asAdmin)
const { stderr, stdout } = await run('xst', ['package', 'install', 'spec/fixtures/test-app.xar'], asAdmin)
if (stderr) {
st.fail(stderr)
st.end()
Expand All @@ -72,7 +72,7 @@ test('single valid package', async function (t) {

test('single broken package', async function (t) {
t.test(async function (st) {
const { stderr, stdout } = await run('xst', ['install', 'spec/fixtures/broken-test-app.xar'], asAdmin)
const { stderr, stdout } = await run('xst', ['package', 'install', 'spec/fixtures/broken-test-app.xar'], asAdmin)

const lines = stdout.split('\n')
st.equal(lines[0], 'Install broken-test-app.xar on https://localhost:8443')
Expand All @@ -86,7 +86,7 @@ test('single broken package', async function (t) {

test('multiple valid packages', async function (t) {
t.test('twice the same package', async function (st) {
const { stderr, stdout } = await run('xst', ['install', 'spec/fixtures/test-app.xar', 'spec/fixtures/test-app.xar'], asAdmin)
const { stderr, stdout } = await run('xst', ['package', 'install', 'spec/fixtures/test-app.xar', 'spec/fixtures/test-app.xar'], asAdmin)
if (stderr) {
console.error(stderr)
st.fail(stderr)
Expand Down Expand Up @@ -114,7 +114,7 @@ test('multiple valid packages', async function (t) {

test('multiple packages', async function (t) {
t.test('first is broken', async function (st) {
const { stderr, stdout } = await run('xst', ['install', 'spec/fixtures/broken-test-app.xar', 'spec/fixtures/test-app.xar'], asAdmin)
const { stderr, stdout } = await run('xst', ['package', 'install', 'spec/fixtures/broken-test-app.xar', 'spec/fixtures/test-app.xar'], asAdmin)
if (stdout) {
st.equal(stdout, 'Install broken-test-app.xar on https://localhost:8443\n✔︎ uploaded\n')
}
Expand All @@ -133,7 +133,7 @@ test('multiple packages', async function (t) {

test('multiple packages', async function (t) {
t.test('second is broken', async function (st) {
const { stderr, stdout } = await run('xst', ['install', 'spec/fixtures/test-app.xar', 'spec/fixtures/broken-test-app.xar'], asAdmin)
const { stderr, stdout } = await run('xst', ['package', 'install', 'spec/fixtures/test-app.xar', 'spec/fixtures/broken-test-app.xar'], asAdmin)

const lines = stdout.split('\n')
st.equal(lines[0], 'Install test-app.xar on https://localhost:8443')
Expand All @@ -155,7 +155,7 @@ test('multiple packages', async function (t) {
})

test('error', async function (t) {
const { stderr, stdout } = await run('xst', ['i', 'asdf'], asAdmin)
const { stderr, stdout } = await run('xst', ['pkg', 'i', 'asdf'], asAdmin)
if (stdout) {
t.fail(stdout)
return
Expand All @@ -164,7 +164,7 @@ test('error', async function (t) {
})

test('error file not found', async function (t) {
const { stderr, stdout } = await run('xst', ['i', 'asdf'], asAdmin)
const { stderr, stdout } = await run('xst', ['pkg', 'i', 'asdf'], asAdmin)
if (stdout) {
t.fail(stdout)
return
Expand All @@ -173,7 +173,7 @@ test('error file not found', async function (t) {
})

test('error install as guest', async function (t) {
const { stderr, stdout } = await run('xst', ['i', 'spec/fixtures/test-app.xar'])
const { stderr, stdout } = await run('xst', ['pkg', 'i', 'spec/fixtures/test-app.xar'])
if (stdout) {
t.fail(stdout)
return
Expand Down

0 comments on commit a079442

Please sign in to comment.