Skip to content

Commit

Permalink
Refactor delta
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 25, 2019
1 parent 41d31e9 commit 69592ee
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/bin/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { ALL_CONFIG } from '../config/all.js'
import { STORE_CONFIG } from '../config/store.js'

export const REMOVE_COMMAND = {
input: 'remove [benchmark]',
input: 'remove [delta]',
description: 'Remove a previous benchmark',

config: { ...ALL_CONFIG, ...STORE_CONFIG },

usage: `$0 [options] remove [integer|date|time]
usage: `$0 [options] remove [delta]
Remove a previous benchmark.
The argument can be:
The 'delta' argument can be:
- nothing: remove the last benchmark
- integer: remove the {integer} previous benchmark
- a date|time: remove the last benchmark before that date|time.
Expand Down
6 changes: 3 additions & 3 deletions src/bin/commands/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SELECT_CONFIG } from '../config/select.js'
import { REPORT_CONFIG } from '../config/report.js'

export const SHOW_COMMAND = {
input: 'show [benchmark]',
input: 'show [delta]',
description: 'Show a previous benchmark',

config: {
Expand All @@ -14,11 +14,11 @@ export const SHOW_COMMAND = {
...REPORT_CONFIG,
},

usage: `$0 [options] show [integer|date|time]
usage: `$0 [options] show [delta]
Show a previous benchmark.
The argument can be:
The 'delta' argument can be:
- nothing: show the last benchmark
- integer: show the {integer} previous benchmark
- a date|time: show the last benchmark before that date|time.
Expand Down
2 changes: 0 additions & 2 deletions src/bin/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const parseOpts = function(yargs) {
progress,
run,
store,
benchmark,
...opts
} = yargs.parse()

Expand All @@ -19,7 +18,6 @@ export const parseOpts = function(yargs) {
const storeA = normalizeDynamicOpts(store)
const optsA = {
...opts,
[command]: benchmark,
report: reportA,
progress: progressA,
run: runA,
Expand Down
14 changes: 7 additions & 7 deletions src/bin/top.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const addCommand = function(
yargsA,
{ input, description, config, usage, examples },
) {
return yargsA.command(input, description, yargsB =>
addCommandInfo(yargsB, { config, usage, examples }),
return yargsA.command(input, description, commandYargs =>
addCommandInfo(commandYargs, { config, usage, examples }),
)
}

const addCommandInfo = function(yargsA, { config, usage, examples }) {
const yargsB = yargsA.options(config).usage(usage)
return examples.reduce(addExample, yargsB)
const addCommandInfo = function(commandYargs, { config, usage, examples }) {
const commandYargsA = commandYargs.options(config).usage(usage)
return examples.reduce(addExample, commandYargsA)
}

const addExample = function(yargsA, example) {
return yargsA.example(...example)
const addExample = function(commandYargs, example) {
return commandYargs.example(...example)
}
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const run = async function(opts) {

// Show a previous benchmark
export const show = async function(opts) {
const { show: showOpt, ...optsA } = await getOpts('show', opts)
const { delta, ...optsA } = await getOpts('show', opts)

const { group, benchmarks } = await getFromStore(showOpt, optsA)
const { group, benchmarks } = await getFromStore(delta, optsA)

const benchmarkA = await report(group, benchmarks, optsA)

Expand All @@ -39,9 +39,9 @@ export const show = async function(opts) {

// Remove a previous benchmark
export const remove = async function(opts) {
const { remove: removeOpt, ...optsA } = await getOpts('remove', opts)
const { delta, ...optsA } = await getOpts('remove', opts)

const { group, rawBenchmarks } = await getFromStore(removeOpt, optsA)
const { group, rawBenchmarks } = await getFromStore(delta, optsA)

await removeFromStore(group, rawBenchmarks, optsA)

Expand Down
6 changes: 2 additions & 4 deletions src/options/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ const DEFAULT_OPTS = {
progress: { debug: {} },
store: { file: {} },
limit: [],
show: true,
delta: true,
diff: true,
remove: true,
}

const VALID_TIMESTAMPS = [
Expand All @@ -98,7 +97,6 @@ const EXAMPLE_OPTS = {
insert: './README.md',
context: true,
limit: ['taskId=10'],
show: VALID_BENCHMARK_DELTA,
delta: VALID_BENCHMARK_DELTA,
diff: VALID_BENCHMARK_DELTA,
remove: VALID_BENCHMARK_DELTA,
}
17 changes: 5 additions & 12 deletions src/options/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ const normalizeCwd = function({ cwd, ...opts }) {
return { ...opts, cwd: cwdA }
}

// Normalize 'show' option
const normalizeShow = function({ show, ...opts }) {
const showA = normalizeDelta('show', show)
return { ...opts, show: showA }
// Normalize 'delta' option
const normalizeDeltaOpt = function({ delta, ...opts }) {
const deltaA = normalizeDelta('delta', delta)
return { ...opts, delta: deltaA }
}

// Normalize 'diff' option
Expand All @@ -76,12 +76,6 @@ const normalizeDiff = function({ diff, ...opts }) {
return { ...opts, diff: diffA }
}

// Normalize 'remove' option
const normalizeRemove = function({ remove, ...opts }) {
const removeA = normalizeDelta('remove', remove)
return { ...opts, remove: removeA }
}

const NORMALIZERS = [
normalizeFiles,
normalizeTasks,
Expand All @@ -90,8 +84,7 @@ const NORMALIZERS = [
normalizeDuration,
normalizeCwd,
normalizeProgress,
normalizeShow,
normalizeDeltaOpt,
normalizeDiff,
normalizeRemove,
normalizeLimits,
]

0 comments on commit 69592ee

Please sign in to comment.