Skip to content

Commit

Permalink
feature: add yesterday arg to list command
Browse files Browse the repository at this point in the history
  • Loading branch information
f3rno64 committed Dec 17, 2023
1 parent 1daa78b commit 48c7420
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const COMMAND_CONFIG = {
O.HumanizeOption,
O.SinceOption,
O.TodayOption,
O.AllOption
O.AllOption,
O.YesterdayOption
])
}

Expand All @@ -35,14 +36,24 @@ interface ListCommandArgs {
all?: boolean
since?: string
today?: boolean
yesterday?: boolean
humanize?: boolean
}

const handler = (args: ListCommandArgs) => {
const { humanize, today, since, all, ago, sheets: sheetNames, db } = args

if (!_isEmpty(since) && today) {
throw new Error('Cannot use both --since and --today')
const {
yesterday,
humanize,
today,
since,
all,
ago,
sheets: sheetNames,
db
} = args

if (!_isEmpty(since) && (today || yesterday)) {
throw new Error('Cannot use --since, --today, and --yesterday together')
}

const activeSheetName = db.getActiveSheetName()
Expand All @@ -66,7 +77,9 @@ const handler = (args: ListCommandArgs) => {
? parseDate(since)
: today
? D.getStartOfDayDate()
: null
: yesterday
? D.getStartOfDayDate(new Date(Date.now() - D.getDaysMS(1)))
: null

const filteredSheets =
sinceDate === null
Expand Down
2 changes: 2 additions & 0 deletions src/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import DescriptionOption from './description'
import YesterdayOption from './yesterday'
import HumanizeOption from './humanize'
import HostnameOption from './hostname'
import SheetsOption from './sheets'
Expand All @@ -17,6 +18,7 @@ import setup from './setup'

export {
DescriptionOption,
YesterdayOption,
HumanizeOption,
HostnameOption,
DeleteOption,
Expand Down
12 changes: 12 additions & 0 deletions src/options/yesterday.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { type YArgsOptionDefinition } from '../types'

const YESTERDAY_OPTION: YArgsOptionDefinition = [
'yesterday',
{
describe: 'Show results from yesterday',
alias: 'y',
type: 'boolean'
}
]

export default YESTERDAY_OPTION

0 comments on commit 48c7420

Please sign in to comment.