micktagger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +18 -0
- data/README.md +32 -0
- data/bin/mt +4 -0
- data/empty.yaml +0 -0
- data/lib/micktagger/cli.rb +42 -0
- data/lib/micktagger/dotfile_handler.rb +38 -0
- data/lib/micktagger/version.rb +3 -0
- data/lib/micktagger.rb +8 -0
- data/micktagger.gemspec +22 -0
- data/spec/integration/mt_spec.rb +31 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/dotfile_helpers.rb +11 -0
- data/spec/support/env_helpers.rb +6 -0
- data/spec/unit/dotfile_handler_spec.rb +60 -0
- metadata +86 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.swp
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
micktagger (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rspec (2.11.0)
|
11
|
+
rspec-core (~> 2.11.0)
|
12
|
+
rspec-expectations (~> 2.11.0)
|
13
|
+
rspec-mocks (~> 2.11.0)
|
14
|
+
rspec-core (2.11.1)
|
15
|
+
rspec-expectations (2.11.2)
|
16
|
+
diff-lcs (~> 1.1.3)
|
17
|
+
rspec-mocks (2.11.1)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
micktagger!
|
24
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2012 Thorsten Ball
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# MickTagger
|
2
|
+
|
3
|
+
MickTagger is a command line utility that allows you to tag files.
|
4
|
+
|
5
|
+
It only uses JSON file placed in your home directory as `.micktagger.json` to
|
6
|
+
save those file and tags associations.
|
7
|
+
|
8
|
+
## Usage & Examples
|
9
|
+
|
10
|
+
```
|
11
|
+
$ mt -a important Gemfile
|
12
|
+
$ mt -l important
|
13
|
+
/Users/mrnugget/code/micktagger/Gemfile
|
14
|
+
$ mt -a to_be_deleted ~/tmp/git_testing
|
15
|
+
$ mt -a to_be_deleted ~/tmp/install.zip
|
16
|
+
$ mt -l to_be_deleted
|
17
|
+
/Users/mrnugget/tmp/git_testing
|
18
|
+
/Users/mrnugget/tmp/install.zip
|
19
|
+
$ mt -d to_be_deleted ~/tmp/install.zip
|
20
|
+
$ mt -l to_be_deleted
|
21
|
+
/Users/mrnugget/tmp/git_testing
|
22
|
+
```
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
`gem install micktagger`
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
MickTagger is released under the MIT license:
|
31
|
+
|
32
|
+
- www.opensource.org/licenses/MIT
|
data/bin/mt
ADDED
data/empty.yaml
ADDED
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module MickTagger
|
2
|
+
class CLI
|
3
|
+
def self.dance!
|
4
|
+
dotfile_handler = DotfileHandler.new
|
5
|
+
parser = OptionParser.new
|
6
|
+
|
7
|
+
params = {}
|
8
|
+
output_lines = []
|
9
|
+
|
10
|
+
parser.on('-a', '--add [TAG]', String) do |tag|
|
11
|
+
params[:action] = :add
|
12
|
+
params[:tag] = tag
|
13
|
+
end
|
14
|
+
|
15
|
+
parser.on('-d', '--delete [TAG]', String) do |tag|
|
16
|
+
params[:action] = :delete
|
17
|
+
params[:tag] = tag
|
18
|
+
end
|
19
|
+
|
20
|
+
parser.on('-l', '--list [TAG]', String) do |tag|
|
21
|
+
params[:action] = :list
|
22
|
+
params[:tag] = tag
|
23
|
+
end
|
24
|
+
|
25
|
+
files = parser.parse!
|
26
|
+
files.map! {|file| File.expand_path(file) }
|
27
|
+
|
28
|
+
case params[:action]
|
29
|
+
when :add
|
30
|
+
files.each { |file| dotfile_handler.add_tag_to(file, params[:tag]) }
|
31
|
+
when :delete
|
32
|
+
files.each { |file| dotfile_handler.remove_tag_from(file, params[:tag]) }
|
33
|
+
when :list
|
34
|
+
output_lines << dotfile_handler.files_for(params[:tag])
|
35
|
+
end
|
36
|
+
|
37
|
+
dotfile_handler.save_file!
|
38
|
+
|
39
|
+
output_lines.each { |line| $stdout.puts(line) }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module MickTagger
|
2
|
+
class DotfileHandler
|
3
|
+
def initialize
|
4
|
+
@file_path = "#{ENV['HOME']}/.micktagger.json"
|
5
|
+
@content = load_content(@file_path)
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_tag_to(file, tag)
|
9
|
+
@content[file] = [] unless @content[file]
|
10
|
+
@content[file] << tag
|
11
|
+
@content[file].uniq!
|
12
|
+
end
|
13
|
+
|
14
|
+
def remove_tag_from(file, tag)
|
15
|
+
@content[file].delete(tag)
|
16
|
+
@content.delete(file) if @content[file].empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_file!
|
20
|
+
File.open(@file_path, 'w') { |dotfile| dotfile.write(@content.to_json) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def files_for(tag)
|
24
|
+
@content.select { |file, tags| tags.include?(tag) }.keys
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def load_content(path)
|
30
|
+
File.exists?(path) ? bootstrap_content(path) : {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def bootstrap_content(path)
|
34
|
+
existing_content = File.read(path)
|
35
|
+
existing_content.empty? ? {} : JSON.parse(existing_content)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/micktagger.rb
ADDED
data/micktagger.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../lib/micktagger/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Thorsten Ball"]
|
5
|
+
gem.email = ["mrnugget@gmail.com"]
|
6
|
+
gem.description = %q{MickTagger is a command line utility that allows you to tag files.}
|
7
|
+
gem.summary = %q{
|
8
|
+
With MickTagger you can tag files, list files tagged with a specified tag,
|
9
|
+
remove tags and do cool stuff — all on the command line!
|
10
|
+
It only needs a small json dotfile in your homedirectory to save that information.
|
11
|
+
}
|
12
|
+
gem.homepage = "http://www.github.com/mrnugget/micktagger"
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.name = "micktagger"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = MickTagger::VERSION
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'micktagger command line interface' do
|
4
|
+
it 'allows me to add tags to a file, list the files of for tag and remove tags' do
|
5
|
+
readme_full_path = File.expand_path('../../../README.md', __FILE__)
|
6
|
+
|
7
|
+
`mt -a important README.md`
|
8
|
+
|
9
|
+
dotfile = read_and_parse_fake_dotfile
|
10
|
+
dotfile[readme_full_path].should == ['important']
|
11
|
+
|
12
|
+
output = `mt -l important`
|
13
|
+
output.should match(readme_full_path)
|
14
|
+
|
15
|
+
`mt -a markdown README.md`
|
16
|
+
|
17
|
+
dotfile = read_and_parse_fake_dotfile
|
18
|
+
dotfile[readme_full_path].should include('important')
|
19
|
+
dotfile[readme_full_path].should include('markdown')
|
20
|
+
|
21
|
+
`mt -d important README.md`
|
22
|
+
|
23
|
+
dotfile = read_and_parse_fake_dotfile
|
24
|
+
dotfile[readme_full_path].should_not include('important')
|
25
|
+
|
26
|
+
`mt -d markdown README.md`
|
27
|
+
|
28
|
+
dotfile = read_and_parse_fake_dotfile
|
29
|
+
dotfile.should_not include(readme_full_path)
|
30
|
+
end
|
31
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'micktagger'
|
5
|
+
|
6
|
+
Dir[File.expand_path(File.dirname(__FILE__) + '/support/**/*.rb')].each {|f| require f}
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.before(:each) do
|
10
|
+
setup_test_env
|
11
|
+
delete_fake_dotfile
|
12
|
+
end
|
13
|
+
|
14
|
+
config.after(:each) do
|
15
|
+
delete_fake_dotfile
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
def fake_dotfile
|
2
|
+
File.expand_path('../../fixtures/fake_home/.micktagger.json', __FILE__)
|
3
|
+
end
|
4
|
+
|
5
|
+
def delete_fake_dotfile
|
6
|
+
File.delete(fake_dotfile) if File.exists?(fake_dotfile)
|
7
|
+
end
|
8
|
+
|
9
|
+
def read_and_parse_fake_dotfile
|
10
|
+
JSON.parse(File.read(fake_dotfile))
|
11
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
def setup_test_env
|
2
|
+
# Modifying the PATH to prioritize the current executable
|
3
|
+
ENV['PATH'] = "#{File.expand_path('../../../bin/', __FILE__)}:#{ENV['PATH']}"
|
4
|
+
# Modifying HOME to test the micktagger dotfile
|
5
|
+
ENV['HOME'] = File.expand_path('../../fixtures/fake_home/', __FILE__)
|
6
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MickTagger::DotfileHandler do
|
4
|
+
let(:handler) do
|
5
|
+
MickTagger::DotfileHandler.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#add_tag_to' do
|
9
|
+
it 'allows me to add a tag to a file' do
|
10
|
+
handler.add_tag_to('/Users/mrnugget/todo.txt', 'important')
|
11
|
+
handler.save_file!
|
12
|
+
|
13
|
+
dotfile = read_and_parse_fake_dotfile
|
14
|
+
dotfile['/Users/mrnugget/todo.txt'].should == ['important']
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'allows me to add several tags to a file' do
|
18
|
+
handler.add_tag_to('/Users/mrnugget/readme.md', 'markdown')
|
19
|
+
handler.add_tag_to('/Users/mrnugget/readme.md', 'important')
|
20
|
+
handler.save_file!
|
21
|
+
|
22
|
+
dotfile = read_and_parse_fake_dotfile
|
23
|
+
dotfile['/Users/mrnugget/readme.md'].should == ['markdown', 'important']
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'does not keep duplicate tags in the file' do
|
27
|
+
handler.add_tag_to('/Users/mrnugget/todo.txt', 'important')
|
28
|
+
handler.add_tag_to('/Users/mrnugget/todo.txt', 'important')
|
29
|
+
handler.save_file!
|
30
|
+
|
31
|
+
dotfile = read_and_parse_fake_dotfile
|
32
|
+
dotfile['/Users/mrnugget/todo.txt'].should == ['important']
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#remove_tag_from' do
|
37
|
+
before(:each) do
|
38
|
+
handler.add_tag_to('/Users/mrnugget/todo.txt', 'important')
|
39
|
+
handler.add_tag_to('/Users/mrnugget/readme.md', 'markdown')
|
40
|
+
handler.add_tag_to('/Users/mrnugget/readme.md', 'important')
|
41
|
+
handler.save_file!
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'allows me to remove tags from a file' do
|
45
|
+
handler.remove_tag_from('/Users/mrnugget/readme.md', 'markdown')
|
46
|
+
handler.save_file!
|
47
|
+
|
48
|
+
dotfile = read_and_parse_fake_dotfile
|
49
|
+
dotfile['/Users/mrnugget/readme.md'].should_not include('markdown')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'removes files from dotfile if they have not tags' do
|
53
|
+
handler.remove_tag_from('/Users/mrnugget/todo.txt', 'important')
|
54
|
+
handler.save_file!
|
55
|
+
|
56
|
+
dotfile = read_and_parse_fake_dotfile
|
57
|
+
dotfile.should_not include('/Users/mrnugget/todo.txt')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: micktagger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thorsten Ball
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: MickTagger is a command line utility that allows you to tag files.
|
31
|
+
email:
|
32
|
+
- mrnugget@gmail.com
|
33
|
+
executables:
|
34
|
+
- mt
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- bin/mt
|
44
|
+
- empty.yaml
|
45
|
+
- lib/micktagger.rb
|
46
|
+
- lib/micktagger/cli.rb
|
47
|
+
- lib/micktagger/dotfile_handler.rb
|
48
|
+
- lib/micktagger/version.rb
|
49
|
+
- micktagger.gemspec
|
50
|
+
- spec/integration/mt_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- spec/support/dotfile_helpers.rb
|
53
|
+
- spec/support/env_helpers.rb
|
54
|
+
- spec/unit/dotfile_handler_spec.rb
|
55
|
+
homepage: http://www.github.com/mrnugget/micktagger
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.23
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: With MickTagger you can tag files, list files tagged with a specified tag,
|
79
|
+
remove tags and do cool stuff — all on the command line! It only needs a small json
|
80
|
+
dotfile in your homedirectory to save that information.
|
81
|
+
test_files:
|
82
|
+
- spec/integration/mt_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/support/dotfile_helpers.rb
|
85
|
+
- spec/support/env_helpers.rb
|
86
|
+
- spec/unit/dotfile_handler_spec.rb
|