mirror of https://github.com/Seich/Beau.git
Improved prompt descriptions. (#167)
I was really naive with combining urls and paths. This should fix it.
This commit is contained in:
parent
3cb6851ead
commit
f82a529ebe
|
|
@ -4,6 +4,7 @@ const clc = require('cli-color')
|
||||||
const prompts = require('prompts')
|
const prompts = require('prompts')
|
||||||
const { Line, Spinner } = require('clui')
|
const { Line, Spinner } = require('clui')
|
||||||
const { flags } = require('@oclif/command')
|
const { flags } = require('@oclif/command')
|
||||||
|
const { expandPath } = require('../../../src/shared')
|
||||||
|
|
||||||
class RequestCommand extends Base {
|
class RequestCommand extends Base {
|
||||||
prettyOutput(res, verbose = false) {
|
prettyOutput(res, verbose = false) {
|
||||||
|
|
@ -69,7 +70,7 @@ class RequestCommand extends Base {
|
||||||
({ VERB, ALIAS, ENDPOINT, PATH }) => ({
|
({ VERB, ALIAS, ENDPOINT, PATH }) => ({
|
||||||
title: `${VERB} ${PATH} - ${ALIAS}`,
|
title: `${VERB} ${PATH} - ${ALIAS}`,
|
||||||
value: ALIAS,
|
value: ALIAS,
|
||||||
description: `${ENDPOINT}${PATH}`
|
description: expandPath(ENDPOINT, PATH)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
endpoint: https://pokeapi.co/api/v2
|
endpoint: https://pokeapi.co/api/v2/
|
||||||
|
|
||||||
# Try replacing this pokemon using params:
|
# Try replacing this pokemon using params:
|
||||||
# beau request get-pokemon -P "pokemon=dragapult"
|
# beau request get-pokemon -P "pokemon=dragapult"
|
||||||
|
|
@ -6,6 +6,8 @@ environment:
|
||||||
_:
|
_:
|
||||||
pokemon: ditto
|
pokemon: ditto
|
||||||
|
|
||||||
|
cookiejar: true
|
||||||
|
|
||||||
GET /pokemon/$env._.pokemon: get-pokemon
|
GET /pokemon/$env._.pokemon: get-pokemon
|
||||||
GET $get-pokemon.body.location_area_encounters: get-encounters
|
GET $get-pokemon.body.location_area_encounters: get-encounters
|
||||||
|
|
||||||
|
|
@ -17,3 +19,19 @@ POST https://httpbin.org/anything:
|
||||||
- alias: post-pokemon-type
|
- alias: post-pokemon-type
|
||||||
payload:
|
payload:
|
||||||
type: $get-pokemon.body.types.0.type.name
|
type: $get-pokemon.body.types.0.type.name
|
||||||
|
|
||||||
|
- alias: form-submission
|
||||||
|
form:
|
||||||
|
name: Dragapult
|
||||||
|
|
||||||
|
- alias: file-upload
|
||||||
|
formdata:
|
||||||
|
name: Beau
|
||||||
|
logo: $[createReadStream('../media/beau.png')]
|
||||||
|
|
||||||
|
GET https://httpbin.org/status/418: teapot
|
||||||
|
|
||||||
|
GET https://httpbin.org/cookies/set:
|
||||||
|
alias: set-cookies
|
||||||
|
params:
|
||||||
|
hello: World
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ const {
|
||||||
UpperCaseKeys,
|
UpperCaseKeys,
|
||||||
removeOptionalKeys,
|
removeOptionalKeys,
|
||||||
toKebabCase,
|
toKebabCase,
|
||||||
replaceInObject
|
replaceInObject,
|
||||||
|
expandPath
|
||||||
} = require('../shared')
|
} = require('../shared')
|
||||||
|
|
||||||
describe('Shared Utilities', () => {
|
describe('Shared Utilities', () => {
|
||||||
|
|
@ -72,4 +73,26 @@ describe('Shared Utilities', () => {
|
||||||
expect(replaceInObject(a, (obj) => 'a')).toEqual({ b: 'a', c: 'a' })
|
expect(replaceInObject(a, (obj) => 'a')).toEqual({ b: 'a', c: 'a' })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('expandPath', () => {
|
||||||
|
test.each([
|
||||||
|
['https://alchem.ee', 'api/v1/hello'],
|
||||||
|
['https://alchem.ee/', '/api/v1/hello'],
|
||||||
|
['https://alchem.ee', '/api/v1/hello'],
|
||||||
|
['https://alchem.ee/', 'api/v1/hello']
|
||||||
|
])(
|
||||||
|
'should add a base url to the path is the path is not a url: %s, %s',
|
||||||
|
(url, path) => {
|
||||||
|
expect(expandPath(url, path)).toEqual(
|
||||||
|
'https://alchem.ee/api/v1/hello'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
it('should return the path if its a fully fledged url on its own', () => {
|
||||||
|
expect(
|
||||||
|
expandPath('https://alchem.ee', 'https://martianwabbit.com')
|
||||||
|
).toEqual('https://martianwabbit.com')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,14 @@ const isUrl = function (str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const expandPath = (url, path) => {
|
||||||
|
if (isUrl(path)) {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
return url.replace(/\/+$/, '') + '/' + path.replace(/^\/+/, '')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
requestRegex,
|
requestRegex,
|
||||||
replacementRegex,
|
replacementRegex,
|
||||||
|
|
@ -86,5 +94,6 @@ module.exports = {
|
||||||
toKebabCase,
|
toKebabCase,
|
||||||
replaceInObject,
|
replaceInObject,
|
||||||
moduleVersion,
|
moduleVersion,
|
||||||
isUrl
|
isUrl,
|
||||||
|
expandPath
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue