Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbata committed Mar 26, 2021
1 parent ce2c26b commit 29c229b
Show file tree
Hide file tree
Showing 9 changed files with 1,402 additions and 1,402 deletions.
20 changes: 10 additions & 10 deletions bin/todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,37 @@ def execute(arguments)
begin
setup
action = arguments.first
args = arguments[1..-1] || []
args = arguments.drop(1)
case action
when 'add'
raise action + ' command requires at least one parameter' if args.nil? || args.empty?
add(args.join(' '))
when 'start'
args.length > 0 ? change_state(args.first.to_i, 'started', (args[1..-1] || []).join(' ')) : list(nil, [':started'])
args.length > 0 ? change_state(args.first.to_i, 'started', args.drop(1).join(' ')) : list(nil, [':started'])
when 'done'
args.length > 0 ? change_state(args.first.to_i, 'done', (args[1..-1] || []).join(' ')) : list(nil, [':done'])
args.length > 0 ? change_state(args.first.to_i, 'done', args.drop(1).join(' ')) : list(nil, [':done'])
when 'block'
args.length > 0 ? change_state(args.first.to_i, 'blocked', (args[1..-1] || []).join(' ')) : list(nil, [':blocked'])
args.length > 0 ? change_state(args.first.to_i, 'blocked', args.drop(1).join(' ')) : list(nil, [':blocked'])
when 'reset'
args.length > 0 ? change_state(args.first.to_i, 'new', (args[1..-1] || []).join(' ')) : list(nil, [':new'])
args.length > 0 ? change_state(args.first.to_i, 'new', args.drop(1).join(' ')) : list(nil, [':new'])
when 'prio'
raise action + ' command requires at least one parameter' if args.length < 1
set_priority(args.first.to_i, (args[1..-1] || []).join(' '))
set_priority(args.first.to_i, args.drop(1).join(' '))
when 'due'
raise action + ' command requires at least one parameter' if args.length < 1
due_date(args.first.to_i, (args[1..-1] || []).join(' '))
due_date(args.first.to_i, args.drop(1).join(' '))
when 'append'
raise action + ' command requires at least two parameters' if args.length < 2
append(args.first.to_i, args[1..-1].join(' '))
append(args.first.to_i, args.drop(1).join(' '))
when 'rename'
raise action + ' command requires at least two parameters' if args.length < 2
rename(args.first.to_i, args[1..-1].join(' '))
rename(args.first.to_i, args.drop(1).join(' '))
when 'del'
raise action + ' command requires exactly one parameter' if args.length != 1
delete(args.first.to_i)
when 'note'
raise action + ' command requires at least two parameters' if args.length < 2
add_note(args.first.to_i, args[1..-1].join(' '))
add_note(args.first.to_i, args.drop(1).join(' '))
when 'delnote'
raise action + ' command requires one or two parameters' if args.length < 1 || args.length > 2
delete_note(args.first.to_i, args[1])
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "todo-jsonl",
"version": "1.0.6",
"version": "1.0.7",
"description": "todo list manager on the command-line inspired by todo.txt using the jsonl format",
"main": "todo.js",
"bin": {
Expand Down
6 changes: 3 additions & 3 deletions node/test/todo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ const today = () => new Date().toISOString().replace(/T.+/, '')
let todoPath

describe("todo list manager", () => {
before(() => {
before("setup environment", () => {
const originalHomeDir = os.homedir()
process.env.HOME = process.cwd()
process.env.USERPROFILE = process.cwd()
assert.notEqual(originalHomeDir, os.homedir())
todoPath = path.join(process.cwd(), 'todo.jsonl')
})

beforeEach(() => {
beforeEach("add initial task", () => {
if (fs.existsSync(todoPath)) {
fs.unlinkSync(todoPath)
}
execSync('node todo.js add Buy Milk')
})

afterEach(() => {
afterEach("delete todo file", () => {
if (fs.existsSync(todoPath)) {
fs.unlinkSync(todoPath)
}
Expand Down
1,416 changes: 708 additions & 708 deletions node/todo.js

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions node/todo.js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,37 @@ def execute(arguments)
begin
setup
action = arguments.first
args = arguments[1..-1] || []
args = arguments.drop(1)
case action
when 'add'
raise action + ' command requires at least one parameter' if args.nil? || args.empty?
add(args.join(' '))
when 'start'
args.length > 0 ? change_state(args.first.to_i, 'started', (args[1..-1] || []).join(' ')) : list(nil, [':started'])
args.length > 0 ? change_state(args.first.to_i, 'started', args.drop(1).join(' ')) : list(nil, [':started'])
when 'done'
args.length > 0 ? change_state(args.first.to_i, 'done', (args[1..-1] || []).join(' ')) : list(nil, [':done'])
args.length > 0 ? change_state(args.first.to_i, 'done', args.drop(1).join(' ')) : list(nil, [':done'])
when 'block'
args.length > 0 ? change_state(args.first.to_i, 'blocked', (args[1..-1] || []).join(' ')) : list(nil, [':blocked'])
args.length > 0 ? change_state(args.first.to_i, 'blocked', args.drop(1).join(' ')) : list(nil, [':blocked'])
when 'reset'
args.length > 0 ? change_state(args.first.to_i, 'new', (args[1..-1] || []).join(' ')) : list(nil, [':new'])
args.length > 0 ? change_state(args.first.to_i, 'new', args.drop(1).join(' ')) : list(nil, [':new'])
when 'prio'
raise action + ' command requires at least one parameter' if args.length < 1
set_priority(args.first.to_i, (args[1..-1] || []).join(' '))
set_priority(args.first.to_i, args.drop(1).join(' '))
when 'due'
raise action + ' command requires at least one parameter' if args.length < 1
due_date(args.first.to_i, (args[1..-1] || []).join(' '))
due_date(args.first.to_i, args.drop(1).join(' '))
when 'append'
raise action + ' command requires at least two parameters' if args.length < 2
append(args.first.to_i, args[1..-1].join(' '))
append(args.first.to_i, args.drop(1).join(' '))
when 'rename'
raise action + ' command requires at least two parameters' if args.length < 2
rename(args.first.to_i, args[1..-1].join(' '))
rename(args.first.to_i, args.drop(1).join(' '))
when 'del'
raise action + ' command requires exactly one parameter' if args.length != 1
delete(args.first.to_i)
when 'note'
raise action + ' command requires at least two parameters' if args.length < 2
add_note(args.first.to_i, args[1..-1].join(' '))
add_note(args.first.to_i, args.drop(1).join(' '))
when 'delnote'
raise action + ' command requires one or two parameters' if args.length < 1 || args.length > 2
delete_note(args.first.to_i, args[1])
Expand Down
2 changes: 1 addition & 1 deletion todo.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'todo-jsonl'
s.version = '1.0.6'
s.version = '1.0.7'
s.date = '2021-03-26'
s.summary = 'todo list manager on the command-line inspired by todo.txt using the jsonl format'
s.authors = ['Gabor Bata']
Expand Down
Loading

0 comments on commit 29c229b

Please sign in to comment.