ptf 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/ptf +14 -0
- data/bin/setup +7 -0
- data/lib/ptf/client/group.rb +23 -0
- data/lib/ptf/client/summary.rb +23 -0
- data/lib/ptf/client/task.rb +37 -0
- data/lib/ptf/client.rb +39 -0
- data/lib/ptf/commands/group/add.rb +50 -0
- data/lib/ptf/commands/group.rb +9 -0
- data/lib/ptf/commands/init.rb +65 -0
- data/lib/ptf/commands/list.rb +91 -0
- data/lib/ptf/commands/task/create.rb +70 -0
- data/lib/ptf/commands/task/edit.rb +55 -0
- data/lib/ptf/commands/task.rb +67 -0
- data/lib/ptf/commands.rb +13 -0
- data/lib/ptf/config.rb +42 -0
- data/lib/ptf/data/data_file.rb +42 -0
- data/lib/ptf/data/group.rb +107 -0
- data/lib/ptf/data/metadata_file.rb +237 -0
- data/lib/ptf/data.rb +9 -0
- data/lib/ptf/utilities/date.rb +63 -0
- data/lib/ptf/utilities/file_system.rb +83 -0
- data/lib/ptf/utilities.rb +28 -0
- data/lib/ptf/version.rb +3 -0
- data/lib/ptf.rb +10 -0
- data/ptf.gemspec +35 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d061046d970e40aa337b3d7c22d6694c86218ed1
|
4
|
+
data.tar.gz: 2d7f5790adb59b3384be8ee40a8a750a16519202
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2227f3d74a214e752cb2fe504d8a7824a31b949123807c7305127be1f9f172ad2169fc1025cd191d0c05e6a62879f159f591f9f04bef52643b6522403f5398e1
|
7
|
+
data.tar.gz: 5dc3cd5181bedc740c02c8036884b24bd0d936a49c5589426a9e68d8e3ca5298fbc922fd037f6bc7634e5ed7a0a3ea19d17ecca0bc8e4ccd4d71f64b7af01731
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Austin Blatt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# PTF
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ptf`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ptf'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ptf
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ptf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ptf"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/ptf
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ptf
|
2
|
+
module Cli
|
3
|
+
class Group < Thor
|
4
|
+
|
5
|
+
desc "group add GROUP ABBREVIATION", "Create a new group"
|
6
|
+
def add(group, abbrev)
|
7
|
+
Ptf::Commands::Group::Add.add(group, abbrev)
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "group remove", "Remove a group"
|
11
|
+
def remove
|
12
|
+
puts "remove group not implemented"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "group transfer", "Transfer a group to another"
|
16
|
+
def transfer
|
17
|
+
puts "transfer group not implemented"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Ptf
|
2
|
+
module Cli
|
3
|
+
class Summary < Thor
|
4
|
+
|
5
|
+
desc "summary create", "Create a summary"
|
6
|
+
def create
|
7
|
+
puts "summary create not implemented"
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "summary edit", "Edit summary"
|
11
|
+
def edit
|
12
|
+
puts "summary edit not implemented"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "summary show", "Show summary"
|
16
|
+
def show
|
17
|
+
puts "summary show not implemented"
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Ptf
|
2
|
+
module Cli
|
3
|
+
class Task < Thor
|
4
|
+
|
5
|
+
desc "task create", "Create a new task"
|
6
|
+
option :title, :type => :string, :required => true, :aliases => :t
|
7
|
+
option :group, :type => :string, :aliases => :g
|
8
|
+
option :date, :type => :string, :aliases => :d
|
9
|
+
option :estimate, :type => :numeric, :aliases => :e
|
10
|
+
def create
|
11
|
+
Ptf::Commands::Task::Create.create(options[:title], options[:group], options[:date], options[:estimate])
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "task edit ID", "Edit a task"
|
15
|
+
def edit(id)
|
16
|
+
Ptf::Commands::Task::Edit.edit(id.to_i)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "task show ID", "Show a task"
|
20
|
+
def show(id)
|
21
|
+
Ptf::Commands::Task.show(id)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "task close ID", "Mark a task a completed"
|
25
|
+
def close(id)
|
26
|
+
Ptf::Commands::Task.close(id)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "task reopen ID", "Reopen a closed task"
|
30
|
+
def reopen(id)
|
31
|
+
Ptf::Commands::Task.reopen(id)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/lib/ptf/client.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require 'ptf/client/task'
|
4
|
+
require 'ptf/client/group'
|
5
|
+
require 'ptf/client/summary'
|
6
|
+
|
7
|
+
module Ptf
|
8
|
+
module Cli
|
9
|
+
class Application < Thor
|
10
|
+
|
11
|
+
desc "init", "Initialize a new Planning Text File project"
|
12
|
+
long_desc <<-LONGDESC
|
13
|
+
Initializes a new Planning Text File workspace.
|
14
|
+
|
15
|
+
With the -f option it writes over an existing PTF workspace.
|
16
|
+
LONGDESC
|
17
|
+
option :f, :type => :boolean
|
18
|
+
def init
|
19
|
+
Ptf::Commands::Init.init(options[:f])
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "task", "Subcommand to manage tasks"
|
23
|
+
subcommand "task", Task
|
24
|
+
|
25
|
+
desc "group", "Subcommand to manage groups"
|
26
|
+
subcommand "group", Group
|
27
|
+
|
28
|
+
desc "list DELIMIT", "List tasks. Given 'all' or a group name"
|
29
|
+
def list(delimiter)
|
30
|
+
Ptf::Commands::List.list(delimiter)
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "summary", "Subcommand to manage a summary of all tasks"
|
34
|
+
subcommand "summary", Summary
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Ptf
|
2
|
+
module Commands
|
3
|
+
module Group
|
4
|
+
module Add
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def add(group, abbrev)
|
8
|
+
if Ptf::Data::Group.group_exist?(group)
|
9
|
+
puts "Group already exists using the name #{group}."
|
10
|
+
return
|
11
|
+
elsif Ptf::Data::Group.group_exist?(abbrev)
|
12
|
+
puts "Group already exists using the abbreviation #{abbrev}."
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
if abbrev.length > 4
|
17
|
+
puts "Abbreviation cannot be longer than 4 characters."
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
if group != group.downcase
|
22
|
+
puts "Group names must be entirely lowercase."
|
23
|
+
return
|
24
|
+
elsif abbrev != abbrev.upcase
|
25
|
+
puts "Group abbreviations must be entirely uppercase."
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
new_group = Ptf::Data::Group.new(group, abbrev)
|
30
|
+
|
31
|
+
group_file = Ptf::Utilities::FileSystem.group_list_file
|
32
|
+
|
33
|
+
File.open(group_file, 'a') { |f| f.write("#{new_group.to_s}\n") }
|
34
|
+
|
35
|
+
open_dir = Ptf::Utilities::FileSystem.metadata_open_dir
|
36
|
+
closed_dir = Ptf::Utilities::FileSystem.metadata_closed_dir
|
37
|
+
|
38
|
+
[open_dir, closed_dir].each do |d|
|
39
|
+
Dir.mkdir(File.join(d, new_group.name), Ptf::Utilities::FileSystem.file_permission)
|
40
|
+
end
|
41
|
+
|
42
|
+
puts "Added group #{new_group.to_s} successfully!"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Ptf
|
2
|
+
module Commands
|
3
|
+
module Init
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def init(force_override = false)
|
7
|
+
|
8
|
+
default_permissions = Ptf::Utilities::FileSystem.file_permission
|
9
|
+
default_group = Ptf::Data::Group.default_group
|
10
|
+
default_counter = Ptf::Utilities::FileSystem.id_counter_starting_content
|
11
|
+
|
12
|
+
base_dir = Ptf::Utilities::FileSystem.base_dir
|
13
|
+
|
14
|
+
if Dir.exist? base_dir
|
15
|
+
if force_override
|
16
|
+
puts "PTF workspace existed, erasing..."
|
17
|
+
`rm -r #{base_dir}`
|
18
|
+
else
|
19
|
+
puts "A PTF workspace has already been initialized."
|
20
|
+
return
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
Dir.mkdir(base_dir, default_permissions)
|
26
|
+
|
27
|
+
info_dir = Ptf::Utilities::FileSystem.metadata_dir
|
28
|
+
Dir.mkdir(info_dir, default_permissions)
|
29
|
+
|
30
|
+
data_dir = Ptf::Utilities::FileSystem.data_dir
|
31
|
+
Dir.mkdir(data_dir, default_permissions)
|
32
|
+
|
33
|
+
tmp_dir = Ptf::Utilities::FileSystem.tmp_dir
|
34
|
+
Dir.mkdir(tmp_dir, default_permissions)
|
35
|
+
|
36
|
+
open_dir = Ptf::Utilities::FileSystem.metadata_open_dir
|
37
|
+
Dir.mkdir(open_dir, default_permissions)
|
38
|
+
|
39
|
+
closed_dir = Ptf::Utilities::FileSystem.metadata_closed_dir
|
40
|
+
Dir.mkdir(closed_dir, default_permissions)
|
41
|
+
|
42
|
+
Dir.mkdir(File.join(open_dir, default_group.name), default_permissions)
|
43
|
+
Dir.mkdir(File.join(closed_dir, default_group.name), default_permissions)
|
44
|
+
|
45
|
+
counter_file = File.new(Ptf::Utilities::FileSystem.id_counter_file, "w")
|
46
|
+
counter_file.puts default_counter
|
47
|
+
counter_file.close
|
48
|
+
|
49
|
+
group_file = File.new(Ptf::Utilities::FileSystem.group_list_file, "w")
|
50
|
+
group_file.puts default_group.to_s
|
51
|
+
group_file.close
|
52
|
+
rescue Exception => e
|
53
|
+
puts "Failed to create PTF workspace."
|
54
|
+
`rm -r #{base_dir}`
|
55
|
+
raise e
|
56
|
+
end
|
57
|
+
|
58
|
+
puts "Created PTF workspace at #{base_dir} successfully!"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Ptf
|
2
|
+
module Commands
|
3
|
+
module List
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def get_metadata_for_group(group)
|
7
|
+
raise ArgumentError, "Group #{group} does not exist." unless Ptf::Data::Group.group_exist?(group)
|
8
|
+
|
9
|
+
group_name = Ptf::Data::Group.get_group(group).name
|
10
|
+
open_group_path = File.join(Ptf::Utilities::FileSystem.metadata_open_dir, group_name)
|
11
|
+
open_group_dir = Dir.new(open_group_path)
|
12
|
+
# closed_group_dir = File.join(Ptf::Utilities::FileSystem.metadata_closed_dir, group)
|
13
|
+
|
14
|
+
open_tasks = open_group_dir.to_a[2..-1].collect do |file|
|
15
|
+
path = File.join(open_group_path, file)
|
16
|
+
|
17
|
+
Ptf::Data::MetadataFile.create_from_file(path)
|
18
|
+
end
|
19
|
+
|
20
|
+
open_tasks
|
21
|
+
end
|
22
|
+
|
23
|
+
def sort_task_arr(task_arr)
|
24
|
+
sorted_arr = task_arr
|
25
|
+
|
26
|
+
sorted_arr.sort! do |a,b|
|
27
|
+
if a.due_date.nil? && b.due_date.nil?
|
28
|
+
a.created_at <=> b.created_at
|
29
|
+
elsif a.due_date.nil?
|
30
|
+
1
|
31
|
+
elsif b.due_date.nil?
|
32
|
+
-1
|
33
|
+
else
|
34
|
+
a.due_date <=> b.due_date
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
sorted_arr
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_list_display(tasks)
|
42
|
+
list_display = ""
|
43
|
+
first = true, past_due = false, have_due_date = true
|
44
|
+
tasks.each do |t|
|
45
|
+
if have_due_date && t.due_date.nil?
|
46
|
+
have_due_date = false
|
47
|
+
list_display += "\n" unless first
|
48
|
+
list_display += "=========== NoDate ===========\n\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
if have_due_date && first && t.due_date <= DateTime.now
|
52
|
+
first = false
|
53
|
+
past_due = true
|
54
|
+
list_display += "============ Past ============\n\n"
|
55
|
+
elsif first && have_due_date
|
56
|
+
first = false
|
57
|
+
list_display += "========== Upcoming ==========\n\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
if have_due_date && past_due && t.due_date > DateTime.now
|
61
|
+
past_due = false
|
62
|
+
list_display += "\n========== Upcoming ==========\n\n"
|
63
|
+
end
|
64
|
+
|
65
|
+
list_display += "#{t.due_date_list_format} #{t.title} (#{t.group.abbreviation} #{t.id})\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
list_display
|
69
|
+
end
|
70
|
+
|
71
|
+
def list(delimiter)
|
72
|
+
if delimiter.downcase == "all"
|
73
|
+
puts "List all not yet implemented"
|
74
|
+
else
|
75
|
+
if !Ptf::Data::Group.group_exist?(delimiter)
|
76
|
+
puts "Group #{delimiter} does not exist."
|
77
|
+
return
|
78
|
+
end
|
79
|
+
|
80
|
+
tasks = get_metadata_for_group(delimiter)
|
81
|
+
tasks = sort_task_arr(tasks)
|
82
|
+
|
83
|
+
puts generate_list_display(tasks)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'digest'
|
2
|
+
|
3
|
+
module Ptf
|
4
|
+
module Commands
|
5
|
+
module Task
|
6
|
+
module Create
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def generate_hash(file_contents)
|
10
|
+
Digest::SHA1.hexdigest file_contents
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_id_number
|
14
|
+
id_file_path = Ptf::Utilities::FileSystem.id_counter_file
|
15
|
+
next_id = File.read(id_file_path).to_i
|
16
|
+
|
17
|
+
id_file = File.new(id_file_path, "w")
|
18
|
+
id_file.write("#{next_id+1}")
|
19
|
+
id_file.close
|
20
|
+
|
21
|
+
next_id
|
22
|
+
end
|
23
|
+
|
24
|
+
def create(t, g, d, e)
|
25
|
+
title = t
|
26
|
+
group = g
|
27
|
+
due_date = d
|
28
|
+
estimate = e
|
29
|
+
|
30
|
+
# Select a group for the task
|
31
|
+
if group.nil?
|
32
|
+
group = Ptf::Data::Group.default_group
|
33
|
+
else
|
34
|
+
if Ptf::Data::Group.group_exist? group
|
35
|
+
group = Ptf::Data::Group.get_group group
|
36
|
+
else
|
37
|
+
puts "Group #{p} does not exist. Create it with ptf group add GROUP ABBREVIATION"
|
38
|
+
return
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Verify the due date
|
43
|
+
if !due_date.nil?
|
44
|
+
due_date = Ptf::Utilities::Date.create_datetime_from_str(due_date)
|
45
|
+
if due_date.nil?
|
46
|
+
puts "Improperly formatted due date '#{d}' given."
|
47
|
+
return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
id = new_id_number
|
52
|
+
|
53
|
+
info_file = Ptf::Data::MetadataFile.create_from_input(title, group, due_date, estimate, id)
|
54
|
+
|
55
|
+
task_info_hash = generate_hash info_file.file_string
|
56
|
+
|
57
|
+
# Append hash to the file
|
58
|
+
info_file.add_content(:hash, task_info_hash)
|
59
|
+
|
60
|
+
data_file = Ptf::Data::DataFile.new(info_file)
|
61
|
+
|
62
|
+
info_file.write_to_file
|
63
|
+
data_file.write_to_file
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Ptf
|
2
|
+
module Commands
|
3
|
+
module Task
|
4
|
+
module Edit
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def verify_file(file)
|
8
|
+
puts "File verification not implemented"
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def edit(id)
|
13
|
+
unless Ptf::Utilities::FileSystem.id_exist? (id)
|
14
|
+
puts "The task #{id} does not exist"
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
metadata_file = Ptf::Utilities::FileSystem.find_file id
|
19
|
+
|
20
|
+
if metadata_file.nil?
|
21
|
+
puts "The task #{id} has been closed. Reopen it with ptf task reopen ###."
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
# Get hash from file
|
26
|
+
data_file_name = Ptf::Data::MetadataFile.create_from_file(metadata_file).hash
|
27
|
+
data_file = File.join(Ptf::Utilities::FileSystem.data_dir, data_file_name)
|
28
|
+
|
29
|
+
# Create a copy in tmp foldere
|
30
|
+
tmp_file_path = File.join(Ptf::Utilities::FileSystem.tmp_dir, data_file_name)
|
31
|
+
FileUtils.copy data_file, tmp_file_path
|
32
|
+
edit_succeeded = system("vim #{data_file}")
|
33
|
+
|
34
|
+
if !edit_succeeded
|
35
|
+
# Move tmp file back, then remove it
|
36
|
+
puts "Vim edit failed. Aborting changes."
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
if verify_file(data_file)
|
41
|
+
puts "Edit successful!"
|
42
|
+
else
|
43
|
+
puts "File verification failed. Aborting changes."
|
44
|
+
end
|
45
|
+
|
46
|
+
# remove tmp file
|
47
|
+
FileUtils.remove_file tmp_file_path
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|