confinicky 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/.document +5 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +70 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +21 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/confinicky +23 -0
- data/confinicky.gemspec +81 -0
- data/lib/confinicky/commands/clean.rb +24 -0
- data/lib/confinicky/commands/duplicates.rb +20 -0
- data/lib/confinicky/commands/list.rb +28 -0
- data/lib/confinicky/commands/remove.rb +32 -0
- data/lib/confinicky/commands/set.rb +31 -0
- data/lib/confinicky/commands/use.rb +27 -0
- data/lib/confinicky/commands.rb +8 -0
- data/lib/confinicky/config.rb +4 -0
- data/lib/confinicky/shell_file.rb +107 -0
- data/lib/confinicky/version.rb +3 -0
- data/lib/confinicky.rb +3 -0
- data/test/helper.rb +37 -0
- data/test/test_confinicky.rb +7 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 569b4825c79f3120de2bfa5dab560a0ae1a439b4
|
4
|
+
data.tar.gz: 976a313cd356e662a4a9fab6ab6b04cfb83c5ac4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2779b1f88c1f1583c7ec5076162213e694be339608f9253a5ef96b16f3327d619ab93d91c658e930b2470b40e79085d403d6a55c00f1f98ba2c4e26f69568692
|
7
|
+
data.tar.gz: f57541874a65455d45c6f16e39dd8b87fd13b8396448bcf441e7c8230baaf1db028d5ef34682c243291038555e7ec3f6c00dedd66cb8015efac7d92f146a7082
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
ruby '2.1.2'
|
2
|
+
source "http://rubygems.org"
|
3
|
+
# Add dependencies required to use your gem here.
|
4
|
+
# Example:
|
5
|
+
# gem "activesupport", ">= 2.3.5"
|
6
|
+
gem 'commander', '~> 4.1'
|
7
|
+
gem "terminal-table", "~> 1.4"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "minitest", "~> 5.4"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", "~> 1.0"
|
15
|
+
gem "jeweler", "~> 2.0"
|
16
|
+
gem "simplecov", "~> 0.9"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.6)
|
5
|
+
builder (3.2.2)
|
6
|
+
commander (4.2.0)
|
7
|
+
highline (~> 1.6.11)
|
8
|
+
descendants_tracker (0.0.4)
|
9
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
10
|
+
docile (1.1.5)
|
11
|
+
faraday (0.9.0)
|
12
|
+
multipart-post (>= 1.2, < 3)
|
13
|
+
git (1.2.8)
|
14
|
+
github_api (0.12.0)
|
15
|
+
addressable (~> 2.3)
|
16
|
+
descendants_tracker (~> 0.0.4)
|
17
|
+
faraday (~> 0.8, < 0.10)
|
18
|
+
hashie (>= 3.2)
|
19
|
+
multi_json (>= 1.7.5, < 2.0)
|
20
|
+
nokogiri (~> 1.6.3)
|
21
|
+
oauth2
|
22
|
+
hashie (3.2.0)
|
23
|
+
highline (1.6.21)
|
24
|
+
jeweler (2.0.1)
|
25
|
+
builder
|
26
|
+
bundler (>= 1.0)
|
27
|
+
git (>= 1.2.5)
|
28
|
+
github_api
|
29
|
+
highline (>= 1.6.15)
|
30
|
+
nokogiri (>= 1.5.10)
|
31
|
+
rake
|
32
|
+
rdoc
|
33
|
+
json (1.8.1)
|
34
|
+
jwt (1.0.0)
|
35
|
+
mini_portile (0.6.0)
|
36
|
+
minitest (5.4.0)
|
37
|
+
multi_json (1.10.1)
|
38
|
+
multi_xml (0.5.5)
|
39
|
+
multipart-post (2.0.0)
|
40
|
+
nokogiri (1.6.3.1)
|
41
|
+
mini_portile (= 0.6.0)
|
42
|
+
oauth2 (1.0.0)
|
43
|
+
faraday (>= 0.8, < 0.10)
|
44
|
+
jwt (~> 1.0)
|
45
|
+
multi_json (~> 1.3)
|
46
|
+
multi_xml (~> 0.5)
|
47
|
+
rack (~> 1.2)
|
48
|
+
rack (1.5.2)
|
49
|
+
rake (10.3.2)
|
50
|
+
rdoc (3.12.2)
|
51
|
+
json (~> 1.4)
|
52
|
+
simplecov (0.9.0)
|
53
|
+
docile (~> 1.1.0)
|
54
|
+
multi_json
|
55
|
+
simplecov-html (~> 0.8.0)
|
56
|
+
simplecov-html (0.8.0)
|
57
|
+
terminal-table (1.4.5)
|
58
|
+
thread_safe (0.3.4)
|
59
|
+
|
60
|
+
PLATFORMS
|
61
|
+
ruby
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
bundler (~> 1.0)
|
65
|
+
commander (~> 4.1)
|
66
|
+
jeweler (~> 2.0)
|
67
|
+
minitest (~> 5.4)
|
68
|
+
rdoc (~> 3.12)
|
69
|
+
simplecov (~> 0.9)
|
70
|
+
terminal-table (~> 1.4)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Jim Jeffers
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
= confinicky
|
2
|
+
|
3
|
+
A simple CLI to manage your environment variables.
|
4
|
+
|
5
|
+
Run 'conficky --help' for a current list of useable commands.
|
6
|
+
|
7
|
+
== Contributing to confinicky
|
8
|
+
|
9
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
10
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
11
|
+
* Fork the project.
|
12
|
+
* Start a feature/bugfix branch.
|
13
|
+
* Commit and push until you are happy with your contribution.
|
14
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
15
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2014 Jim Jeffers. See LICENSE.txt for
|
20
|
+
further details.
|
21
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
+
gem.name = "confinicky"
|
18
|
+
gem.homepage = "http://github.com/jimjeffers/confinicky"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = "A simple CLI to manage environment variables on your local machine."
|
21
|
+
gem.description = "A CLI that allows you to perform basic CRUD for your environment variables."
|
22
|
+
gem.email = "jim@sumocreations.com"
|
23
|
+
gem.authors = ["Jim Jeffers"]
|
24
|
+
gem.executables = ['confinicky']
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Code coverage detail"
|
37
|
+
task :simplecov do
|
38
|
+
ENV['COVERAGE'] = "true"
|
39
|
+
Rake::Task['test'].execute
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "confinicky #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/confinicky
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'commander/import'
|
4
|
+
require 'terminal-table'
|
5
|
+
|
6
|
+
$:.push File.expand_path("../../lib", __FILE__)
|
7
|
+
$:.push File.expand_path("../", __FILE__)
|
8
|
+
|
9
|
+
require 'confinicky'
|
10
|
+
|
11
|
+
HighLine.track_eof = false # Fix for built-in Ruby
|
12
|
+
Signal.trap("INT") {} # Suppress backtrace when exiting command
|
13
|
+
|
14
|
+
program :version, version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
15
|
+
program :description, 'A command-line interface for managing your shell environment variables.'
|
16
|
+
|
17
|
+
program :help, 'Author', 'Jim Jeffers <jim@sumocreations.com>'
|
18
|
+
program :help, 'Website', 'https://github.com/jimjeffers'
|
19
|
+
program :help_formatter, :compact
|
20
|
+
|
21
|
+
default_command :help
|
22
|
+
|
23
|
+
require 'confinicky/commands'
|
data/confinicky.gemspec
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: confinicky 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "confinicky"
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Jim Jeffers"]
|
14
|
+
s.date = "2014-08-10"
|
15
|
+
s.description = "A CLI that allows you to perform basic CRUD for your environment variables."
|
16
|
+
s.email = "jim@sumocreations.com"
|
17
|
+
s.executables = ["confinicky"]
|
18
|
+
s.extra_rdoc_files = [
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.rdoc"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
".document",
|
24
|
+
"Gemfile",
|
25
|
+
"Gemfile.lock",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.rdoc",
|
28
|
+
"Rakefile",
|
29
|
+
"VERSION",
|
30
|
+
"bin/confinicky",
|
31
|
+
"confinicky.gemspec",
|
32
|
+
"lib/confinicky.rb",
|
33
|
+
"lib/confinicky/commands.rb",
|
34
|
+
"lib/confinicky/commands/clean.rb",
|
35
|
+
"lib/confinicky/commands/duplicates.rb",
|
36
|
+
"lib/confinicky/commands/list.rb",
|
37
|
+
"lib/confinicky/commands/remove.rb",
|
38
|
+
"lib/confinicky/commands/set.rb",
|
39
|
+
"lib/confinicky/commands/use.rb",
|
40
|
+
"lib/confinicky/config.rb",
|
41
|
+
"lib/confinicky/shell_file.rb",
|
42
|
+
"lib/confinicky/version.rb",
|
43
|
+
"test/helper.rb",
|
44
|
+
"test/test_confinicky.rb"
|
45
|
+
]
|
46
|
+
s.homepage = "http://github.com/jimjeffers/confinicky"
|
47
|
+
s.licenses = ["MIT"]
|
48
|
+
s.rubygems_version = "2.2.2"
|
49
|
+
s.summary = "A simple CLI to manage environment variables on your local machine."
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 4
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<commander>, ["~> 4.1"])
|
56
|
+
s.add_runtime_dependency(%q<terminal-table>, ["~> 1.4"])
|
57
|
+
s.add_development_dependency(%q<minitest>, ["~> 5.4"])
|
58
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
|
61
|
+
s.add_development_dependency(%q<simplecov>, ["~> 0.9"])
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<commander>, ["~> 4.1"])
|
64
|
+
s.add_dependency(%q<terminal-table>, ["~> 1.4"])
|
65
|
+
s.add_dependency(%q<minitest>, ["~> 5.4"])
|
66
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
69
|
+
s.add_dependency(%q<simplecov>, ["~> 0.9"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<commander>, ["~> 4.1"])
|
73
|
+
s.add_dependency(%q<terminal-table>, ["~> 1.4"])
|
74
|
+
s.add_dependency(%q<minitest>, ["~> 5.4"])
|
75
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0"])
|
78
|
+
s.add_dependency(%q<simplecov>, ["~> 0.9"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
command :clean do |c|
|
2
|
+
c.syntax = 'confinicky clean'
|
3
|
+
c.summary = 'Removes all duplicate export statements in the configuration file.'
|
4
|
+
c.description = ''
|
5
|
+
c.example 'description', 'confinicky clean'
|
6
|
+
|
7
|
+
c.action do |args, options|
|
8
|
+
if Confinicky::ShellFile.has_path?
|
9
|
+
say_error "Please set '#{Confinicky::FILE_PATH_VAR}' to point to your local configuration file."
|
10
|
+
puts "Try running 'confinicky use' for more info."
|
11
|
+
abort
|
12
|
+
end
|
13
|
+
shell_file = Confinicky::ShellFile.new
|
14
|
+
duplicate_count = shell_file.find_duplicates.length
|
15
|
+
say_ok "Your file is clean. No processing was required." and abort if duplicate_count < 1
|
16
|
+
|
17
|
+
if agree "Backup your existing file before continuuing? (y/n)"
|
18
|
+
say_ok "Backup saved to: "+Confinicky::ShellFile.backup!
|
19
|
+
end
|
20
|
+
|
21
|
+
shell_file.clean!
|
22
|
+
say_ok "Your file is clean. #{duplicate_count} duplicate statements have been reduced."
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
command :duplicates do |c|
|
2
|
+
c.syntax = 'confinicky duplicates'
|
3
|
+
c.summary = 'Generates a list of all variables that have multiple export statements.'
|
4
|
+
c.description = ''
|
5
|
+
c.example 'description', 'confinicky duplicates'
|
6
|
+
|
7
|
+
c.action do |args, options|
|
8
|
+
if Confinicky::ShellFile.has_path?
|
9
|
+
say_error "Please set '#{Confinicky::FILE_PATH_VAR}' to point to your local configuration file."
|
10
|
+
puts "Try running 'confinicky use' for more info."
|
11
|
+
abort
|
12
|
+
end
|
13
|
+
shell_file = Confinicky::ShellFile.new
|
14
|
+
duplicates = shell_file.find_duplicates.map{|key, value| [key, value]}
|
15
|
+
table = Terminal::Table.new :rows => duplicates
|
16
|
+
puts table
|
17
|
+
say_ok "Identified #{duplicates.length} variables with multiple 'export' statements in #{Confinicky::ShellFile.file_path}"
|
18
|
+
puts "Run 'confinicky clean' to reduce these statements."
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
command :list do |c|
|
2
|
+
c.syntax = 'confinicky list'
|
3
|
+
c.summary = 'Generates a list of all environment variables set in your configuration file.'
|
4
|
+
c.description = ''
|
5
|
+
c.example 'description', 'confinicky list'
|
6
|
+
|
7
|
+
c.action do |args, options|
|
8
|
+
if Confinicky::ShellFile.has_path?
|
9
|
+
say_error "Please set '#{Confinicky::FILE_PATH_VAR}' to point to your local configuration file."
|
10
|
+
puts "Try running 'confinicky use' for more info."
|
11
|
+
abort
|
12
|
+
end
|
13
|
+
shell_file = Confinicky::ShellFile.new
|
14
|
+
table = Terminal::Table.new do |t|
|
15
|
+
for export in shell_file.exports
|
16
|
+
if export[1].length > 100
|
17
|
+
t.add_row [export[0], export[1][0...100]+"..."]
|
18
|
+
else
|
19
|
+
t.add_row export
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
puts table
|
24
|
+
say_ok "Identified #{shell_file.exports.length} exports in #{Confinicky::ShellFile.file_path}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_command :ls, :list
|
@@ -0,0 +1,32 @@
|
|
1
|
+
command :remove do |c|
|
2
|
+
c.syntax = 'confinicky remove'
|
3
|
+
c.summary = 'Removes an environment variable in your configuration file.'
|
4
|
+
c.description = ''
|
5
|
+
c.example 'description', 'confinicky remove MY_VAR'
|
6
|
+
|
7
|
+
c.action do |args, options|
|
8
|
+
if Confinicky::ShellFile.has_path?
|
9
|
+
say_error "Please set '#{Confinicky::FILE_PATH_VAR}' to point to your local configuration file."
|
10
|
+
puts "Try running 'confinicky use' for more info."
|
11
|
+
abort
|
12
|
+
end
|
13
|
+
|
14
|
+
shell_file = Confinicky::ShellFile.new
|
15
|
+
|
16
|
+
duplicate_count = shell_file.find_duplicates.length
|
17
|
+
if duplicate_count > 0
|
18
|
+
say_error "Your configuration cannot be managed because it currently has duplicate export statements."
|
19
|
+
puts "You must run 'confinicky clean' before you can manage your configuration."
|
20
|
+
abort
|
21
|
+
end
|
22
|
+
|
23
|
+
if shell_file.remove!(args.first)
|
24
|
+
say_ok "Successfully removed '#{args.first}'."
|
25
|
+
puts "Run 'source #{Confinicky::ShellFile.file_path}' or open a new terminal/shell window."
|
26
|
+
else
|
27
|
+
say_error "Could not remove '#{args.first}' please double check to ensure you used the appropriate syntax."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
alias_command :rm, :remove
|
@@ -0,0 +1,31 @@
|
|
1
|
+
command :set do |c|
|
2
|
+
c.syntax = 'confinicky set'
|
3
|
+
c.summary = 'Sets an environment variable in your configuration file.'
|
4
|
+
c.description = ''
|
5
|
+
c.example 'description', 'confinicky set MY_VAR="some value"'
|
6
|
+
|
7
|
+
c.action do |args, options|
|
8
|
+
if Confinicky::ShellFile.has_path?
|
9
|
+
say_error "Please set '#{Confinicky::FILE_PATH_VAR}' to point to your local configuration file."
|
10
|
+
puts "Try running 'confinicky use' for more info."
|
11
|
+
abort
|
12
|
+
end
|
13
|
+
|
14
|
+
shell_file = Confinicky::ShellFile.new
|
15
|
+
|
16
|
+
duplicate_count = shell_file.find_duplicates.length
|
17
|
+
if duplicate_count > 0
|
18
|
+
say_error "Your configuration cannot be managed because it currently has duplicate export statements."
|
19
|
+
puts "You must run 'confinicky clean' before you can manage your configuration."
|
20
|
+
abort
|
21
|
+
end
|
22
|
+
|
23
|
+
if shell_file.set!(args.first)
|
24
|
+
shell_file.write!
|
25
|
+
say_ok "Successfully set '#{args.first}'."
|
26
|
+
puts "Run 'source #{Confinicky::ShellFile.file_path}' or open a new terminal/shell window."
|
27
|
+
else
|
28
|
+
say_error "Could not set '#{args.first}' please double check to ensure you used the appropriate syntax."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
command :use do |c|
|
2
|
+
c.syntax = 'confinicky use'
|
3
|
+
c.summary = 'Appends the confinicky file path shell variable to your configuration.'
|
4
|
+
c.description = ''
|
5
|
+
c.example 'description', 'confinicky use /User/[YOUR_USER_NAME]/.bashrc'
|
6
|
+
|
7
|
+
c.action do |args, options|
|
8
|
+
@file_path = args.first
|
9
|
+
|
10
|
+
if @file_path.nil?
|
11
|
+
say_error "You must specify a path. See example:"
|
12
|
+
puts 'confinicky use /User/[YOUR_USER_NAME]/.bashrc'
|
13
|
+
abort
|
14
|
+
end
|
15
|
+
|
16
|
+
say_error "Could not locate '#{@file_path}'." and abort if !File.exist?(@file_path)
|
17
|
+
|
18
|
+
open(@file_path, 'a') { |f|
|
19
|
+
f.puts "export #{Confinicky::FILE_PATH_VAR}=#{@file_path}"
|
20
|
+
}
|
21
|
+
|
22
|
+
say_ok "Set #{Confinicky::FILE_PATH_VAR} to #{@file_path}"
|
23
|
+
if ENV[Confinicky::FILE_PATH_VAR].nil?
|
24
|
+
puts "Run 'source #{@file_path}' or open a new terminal/shell window."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Confinicky
|
4
|
+
class ShellFile
|
5
|
+
|
6
|
+
##
|
7
|
+
# References the actual file path from the shell configuration.
|
8
|
+
def self.file_path
|
9
|
+
ENV[Confinicky::FILE_PATH_VAR]
|
10
|
+
end
|
11
|
+
|
12
|
+
##
|
13
|
+
# Returns true if the file path has been configured in the environment.
|
14
|
+
def self.has_path?
|
15
|
+
self.file_path.nil?
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Returns true if the file actually exists.
|
20
|
+
def self.exists?
|
21
|
+
File.exists? ENV[Confinicky::FILE_PATH_VAR]
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Copies the current shell file to a temporary location.
|
26
|
+
def self.backup!
|
27
|
+
backup_name = Confinicky::ShellFile.file_path+Time.now.getutc.to_i.to_s+".bak.tmp"
|
28
|
+
FileUtils.cp(Confinicky::ShellFile.file_path, backup_name)
|
29
|
+
backup_name
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Parses the configuration file if it exists.
|
34
|
+
def initialize
|
35
|
+
raise "Config file not found. Please set" if !Confinicky::ShellFile.exists?
|
36
|
+
@exports = []
|
37
|
+
@lines = []
|
38
|
+
file = File.new(Confinicky::ShellFile.file_path, "r")
|
39
|
+
|
40
|
+
while (line = file.gets)
|
41
|
+
if line =~ /\Aexport /
|
42
|
+
export = line.gsub(/\Aexport /,"").split("=")
|
43
|
+
@exports << [export[0], export[1].gsub(/\n/, "")]
|
44
|
+
else
|
45
|
+
@lines << line
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
file.close()
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Detects duplicate definitions.
|
54
|
+
def find_duplicates
|
55
|
+
duplicates = {}
|
56
|
+
@exports.each do |export|
|
57
|
+
duplicates[export[0]] = (duplicates[export[0]].nil?) ? 1 : duplicates[export[0]]+1
|
58
|
+
end
|
59
|
+
duplicates.delete_if { |key,value| value==1}.sort_by{|key,value| value}.reverse
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Returns a list of all exports in alphanumeric order.
|
64
|
+
def exports
|
65
|
+
@exports.sort { |x, y| x[0] <=> y[0] }
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Finds duplicate export statements and replaces them with the actual
|
70
|
+
# value from the environment.
|
71
|
+
def clean!
|
72
|
+
for duplicate in find_duplicates.map{|duplicate| duplicate[0]}
|
73
|
+
@exports.delete_if{ |i| i[0] == duplicate}
|
74
|
+
@exports << [duplicate, ENV[duplicate]]
|
75
|
+
end
|
76
|
+
write!
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Parses an assignment such as "MY_VAR=1234" and injects it into
|
81
|
+
# the exports or updates an existing variable if possible.
|
82
|
+
def set!(assignment)
|
83
|
+
assignment = assignment.split("=")
|
84
|
+
return false if assignment.length < 2
|
85
|
+
remove! assignment[0]
|
86
|
+
@exports << assignment
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# Removes an environment variable if it exists.
|
91
|
+
def remove!(variable_name)
|
92
|
+
@exports.delete_if { |i| i[0] == variable_name }
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Writes a new version of the configuration file.
|
97
|
+
def write!
|
98
|
+
File.open(Confinicky::ShellFile.file_path, "w") do |f|
|
99
|
+
for line in @lines
|
100
|
+
f.write line
|
101
|
+
end
|
102
|
+
f.puts @exports.map{|e| "export #{e.join("=")}"}.join("\n")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
data/lib/confinicky.rb
ADDED
data/test/helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
module SimpleCov::Configuration
|
4
|
+
def clean_filters
|
5
|
+
@filters = []
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
SimpleCov.configure do
|
10
|
+
clean_filters
|
11
|
+
load_profile 'test_frameworks'
|
12
|
+
end
|
13
|
+
|
14
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
15
|
+
add_filter "/.rvm/"
|
16
|
+
end
|
17
|
+
require 'rubygems'
|
18
|
+
require 'bundler'
|
19
|
+
begin
|
20
|
+
Bundler.setup(:default, :development)
|
21
|
+
rescue Bundler::BundlerError => e
|
22
|
+
$stderr.puts e.message
|
23
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
24
|
+
exit e.status_code
|
25
|
+
end
|
26
|
+
|
27
|
+
gem "minitest"
|
28
|
+
require 'minitest/autorun'
|
29
|
+
|
30
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
31
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
32
|
+
require 'confinicky'
|
33
|
+
|
34
|
+
class MiniTest::Unit::Test
|
35
|
+
end
|
36
|
+
|
37
|
+
MiniTest.autorun
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: confinicky
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jim Jeffers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: terminal-table
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
description: A CLI that allows you to perform basic CRUD for your environment variables.
|
112
|
+
email: jim@sumocreations.com
|
113
|
+
executables:
|
114
|
+
- confinicky
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files:
|
117
|
+
- LICENSE.txt
|
118
|
+
- README.rdoc
|
119
|
+
files:
|
120
|
+
- ".document"
|
121
|
+
- Gemfile
|
122
|
+
- Gemfile.lock
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.rdoc
|
125
|
+
- Rakefile
|
126
|
+
- VERSION
|
127
|
+
- bin/confinicky
|
128
|
+
- confinicky.gemspec
|
129
|
+
- lib/confinicky.rb
|
130
|
+
- lib/confinicky/commands.rb
|
131
|
+
- lib/confinicky/commands/clean.rb
|
132
|
+
- lib/confinicky/commands/duplicates.rb
|
133
|
+
- lib/confinicky/commands/list.rb
|
134
|
+
- lib/confinicky/commands/remove.rb
|
135
|
+
- lib/confinicky/commands/set.rb
|
136
|
+
- lib/confinicky/commands/use.rb
|
137
|
+
- lib/confinicky/config.rb
|
138
|
+
- lib/confinicky/shell_file.rb
|
139
|
+
- lib/confinicky/version.rb
|
140
|
+
- test/helper.rb
|
141
|
+
- test/test_confinicky.rb
|
142
|
+
homepage: http://github.com/jimjeffers/confinicky
|
143
|
+
licenses:
|
144
|
+
- MIT
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.2.2
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: A simple CLI to manage environment variables on your local machine.
|
166
|
+
test_files: []
|