confinicky 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/confinicky.gemspec +14 -6
- data/lib/confinicky/commands/clean.rb +26 -8
- data/lib/confinicky/commands/duplicates.rb +31 -9
- data/lib/confinicky/commands/inspect.rb +26 -0
- data/lib/confinicky/commands/list.rb +21 -16
- data/lib/confinicky/commands/remove.rb +27 -13
- data/lib/confinicky/commands/set.rb +27 -16
- data/lib/confinicky/commands/setup.rb +25 -0
- data/lib/confinicky/commands.rb +2 -1
- data/lib/confinicky/config.rb +15 -2
- data/lib/confinicky/configuration_file.rb +89 -0
- data/lib/confinicky/controllers/aliases.rb +23 -0
- data/lib/confinicky/controllers/commands.rb +182 -0
- data/lib/confinicky/controllers/exports.rb +35 -0
- data/lib/confinicky/parsers/command.rb +98 -0
- data/lib/confinicky/parsers/expression.rb +93 -0
- data/lib/confinicky/shell_file.rb +28 -75
- data/lib/confinicky/version.rb +2 -2
- data/lib/confinicky.rb +7 -1
- data/test/test_command_parser.rb +44 -0
- data/test/test_controllers.rb +64 -0
- data/test/{test_confinicky.rb → test_shell_file_parsing.rb} +5 -5
- metadata +13 -5
- data/lib/confinicky/commands/use.rb +0 -27
- data/test/test_file_writing.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52e95dfcb20d5391899a9c04733f21b0b948fb7b
|
4
|
+
data.tar.gz: d4c2cba419829d5c87704dcd99a4b950024cd132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3923507641c3767fe97f20cb853eec13b1c36539b6046e7e32126186612e9029672ea088704e9489c48f3d843cfe82fad2ed21c2834f941fbdb69ab4f3f2b2c
|
7
|
+
data.tar.gz: 33e5fb03f7fc9ebc07b1f0e7cb814b266d3498453707cfcff16181c0e6e6d554465da1a9fa4a5293e528fa09ee4fd4bdcdc12b922e156dda551de1d7f8e4f5d4
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A simple CLI to manage your environment variables.
|
4
4
|
|
5
|
-
Run `
|
5
|
+
Run `cfy --help` for a current list of useable commands.
|
6
6
|
|
7
7
|
## Setup Confinicky
|
8
8
|
|
@@ -58,7 +58,7 @@ You can easily add or adjust an environment variable using `cfy remove` or `cfy
|
|
58
58
|
```
|
59
59
|
→ cfy remove MY_VAR
|
60
60
|
Successfully removed 'MY_VAR'.
|
61
|
-
|
61
|
+
Open a new terminal/shell window for this change to take affect.
|
62
62
|
```
|
63
63
|
|
64
64
|
## Detecting Duplicate Exports
|
data/confinicky.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: confinicky 0.
|
5
|
+
# stub: confinicky 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "confinicky"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Jim Jeffers"]
|
14
|
-
s.date = "2014-08-
|
14
|
+
s.date = "2014-08-24"
|
15
15
|
s.description = "A simple CLI to manage environment variables on your local machine. Perform basic CRUD for your environment variables all in the command line."
|
16
16
|
s.email = "jim@sumocreations.com"
|
17
17
|
s.executables = ["cfy"]
|
@@ -33,17 +33,25 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/confinicky/commands.rb",
|
34
34
|
"lib/confinicky/commands/clean.rb",
|
35
35
|
"lib/confinicky/commands/duplicates.rb",
|
36
|
+
"lib/confinicky/commands/inspect.rb",
|
36
37
|
"lib/confinicky/commands/list.rb",
|
37
38
|
"lib/confinicky/commands/remove.rb",
|
38
39
|
"lib/confinicky/commands/set.rb",
|
39
|
-
"lib/confinicky/commands/
|
40
|
+
"lib/confinicky/commands/setup.rb",
|
40
41
|
"lib/confinicky/config.rb",
|
42
|
+
"lib/confinicky/configuration_file.rb",
|
43
|
+
"lib/confinicky/controllers/aliases.rb",
|
44
|
+
"lib/confinicky/controllers/commands.rb",
|
45
|
+
"lib/confinicky/controllers/exports.rb",
|
46
|
+
"lib/confinicky/parsers/command.rb",
|
47
|
+
"lib/confinicky/parsers/expression.rb",
|
41
48
|
"lib/confinicky/shell_file.rb",
|
42
49
|
"lib/confinicky/version.rb",
|
43
50
|
"test/helper.rb",
|
44
51
|
"test/sample_bash_file.sh",
|
45
|
-
"test/
|
46
|
-
"test/
|
52
|
+
"test/test_command_parser.rb",
|
53
|
+
"test/test_controllers.rb",
|
54
|
+
"test/test_shell_file_parsing.rb"
|
47
55
|
]
|
48
56
|
s.homepage = "http://github.com/jimjeffers/confinicky"
|
49
57
|
s.licenses = ["MIT"]
|
@@ -5,20 +5,38 @@ command :clean do |c|
|
|
5
5
|
c.example 'description', 'cfy clean'
|
6
6
|
|
7
7
|
c.action do |args, options|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
|
9
|
+
# Abort if not yet setup.
|
10
|
+
if !Confinicky::ConfigurationFile.setup?
|
11
|
+
say_error "Confinicky's configuration is not valid or has not been setup."
|
12
|
+
puts "Try running 'cfy setup'."
|
13
|
+
abort
|
14
|
+
end
|
15
|
+
|
16
|
+
# Abort if missing arguments.
|
17
|
+
if args.length < 1
|
18
|
+
say_error "You must specify environment `cfy clean env` or aliases `cfy clean alias`."
|
11
19
|
abort
|
12
20
|
end
|
13
|
-
|
14
|
-
|
21
|
+
|
22
|
+
# Use the appropriate command group controller.
|
23
|
+
command = args[0]
|
24
|
+
command_group = Confinicky::Controllers::Exports.new if command == Confinicky::Arguments::ENVIRONMENT
|
25
|
+
command_group = Confinicky::Controllers::Aliases.new if command == Confinicky::Arguments::ALIAS
|
26
|
+
|
27
|
+
duplicate_count = command_group.duplicates.length
|
15
28
|
say_ok "Your file is clean. No processing was required." and abort if duplicate_count < 1
|
16
29
|
|
17
30
|
if agree "Backup your existing file before continuuing? (y/n)"
|
18
|
-
say_ok "Backup saved to: "+
|
31
|
+
say_ok "Backup saved to: "+command_group.backup!
|
32
|
+
end
|
33
|
+
|
34
|
+
if command_group.clean! && command_group.save!
|
35
|
+
say_ok "Your file is clean. #{duplicate_count} duplicate statements have been reduced."
|
36
|
+
else
|
37
|
+
say_error "There was a problem cleaning the file."
|
38
|
+
puts "Please try editing it manually: #{command_group.path}"
|
19
39
|
end
|
20
40
|
|
21
|
-
shell_file.clean!
|
22
|
-
say_ok "Your file is clean. #{duplicate_count} duplicate statements have been reduced."
|
23
41
|
end
|
24
42
|
end
|
@@ -6,17 +6,39 @@ command :duplicates do |c|
|
|
6
6
|
|
7
7
|
c.action do |args, options|
|
8
8
|
|
9
|
-
if
|
10
|
-
|
11
|
-
|
9
|
+
# Abort if not yet setup.
|
10
|
+
if !Confinicky::ConfigurationFile.setup?
|
11
|
+
say_error "Confinicky's configuration is not valid or has not been setup."
|
12
|
+
puts "Try running 'cfy setup'."
|
12
13
|
abort
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
# Abort if missing arguments.
|
17
|
+
if args.length < 1
|
18
|
+
say_error "You must specify environment `cfy duplicates env` or aliases `cfy duplicates alias`."
|
19
|
+
abort
|
20
|
+
end
|
21
|
+
|
22
|
+
# Use the appropriate command group controller.
|
23
|
+
command = args[0]
|
24
|
+
command_group = Confinicky::Controllers::Exports.new if command == Confinicky::Arguments::ENVIRONMENT
|
25
|
+
command_group = Confinicky::Controllers::Aliases.new if command == Confinicky::Arguments::ALIAS
|
26
|
+
|
27
|
+
# Print out any duplicates.
|
28
|
+
duplicates = command_group.duplicates.map{|key, value| [key, value]}
|
29
|
+
|
30
|
+
if duplicates.length > 0
|
31
|
+
table = Terminal::Table.new :rows => duplicates
|
32
|
+
puts table
|
33
|
+
if command == Confinicky::Arguments::ENVIRONMENT
|
34
|
+
say_ok "Identified #{duplicates.length} variables with multiple 'export' statements in #{command_group.path}"
|
35
|
+
elsif command == Confinicky::Arguments::ALIAS
|
36
|
+
say_ok "Identified #{duplicates.length} alias statements in #{command_group.path}"
|
37
|
+
end
|
38
|
+
puts "Run 'confinicky clean' to reduce these statements."
|
39
|
+
else
|
40
|
+
puts "No duplicate statements found."
|
41
|
+
end
|
42
|
+
|
21
43
|
end
|
22
44
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
command :inspect do |c|
|
2
|
+
c.syntax = 'cfy inspect'
|
3
|
+
c.summary = 'Generates a list of all values for a specified environment variable.'
|
4
|
+
c.description = ''
|
5
|
+
c.example 'Inspect your shell path.', 'cfy inspect PATH'
|
6
|
+
|
7
|
+
c.action do |args, options|
|
8
|
+
|
9
|
+
# Abort if not yet setup.
|
10
|
+
if !Confinicky::ConfigurationFile.setup?
|
11
|
+
say_error "Confinicky's configuration is not valid or has not been setup."
|
12
|
+
puts "Try running 'cfy setup'."
|
13
|
+
abort
|
14
|
+
end
|
15
|
+
|
16
|
+
# Abort if missing arguments.
|
17
|
+
if args.length < 1
|
18
|
+
say_error "You must supply a variable name such as: `cfy inspect MY_VAR`"
|
19
|
+
abort
|
20
|
+
end
|
21
|
+
|
22
|
+
command_group = Confinicky::Controllers::Exports.new
|
23
|
+
puts command_group.inspect(name:args[0], separator:":")
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -1,31 +1,36 @@
|
|
1
1
|
command :list do |c|
|
2
2
|
c.syntax = 'cfy list'
|
3
|
-
c.summary = 'Generates a list of all environment variables set in your configuration file.'
|
3
|
+
c.summary = 'Generates a list of all environment variables and/or aliases set in your configuration file(s).'
|
4
4
|
c.description = ''
|
5
|
-
c.example '
|
5
|
+
c.example 'default', 'cfy list'
|
6
|
+
c.example 'environment variables', 'cfy list env'
|
7
|
+
c.example 'aliases', 'cfy list alias'
|
6
8
|
|
7
9
|
c.action do |args, options|
|
8
10
|
|
9
|
-
if
|
10
|
-
|
11
|
-
|
11
|
+
# Abort if not yet setup.
|
12
|
+
if !Confinicky::ConfigurationFile.setup?
|
13
|
+
say_error "Confinicky's configuration is not valid or has not been setup."
|
14
|
+
puts "Try running 'cfy setup'."
|
12
15
|
abort
|
13
16
|
end
|
14
17
|
|
15
|
-
|
18
|
+
# Use the appropriate command group controller.
|
19
|
+
exports = Confinicky::Controllers::Exports.new
|
20
|
+
aliases = Confinicky::Controllers::Aliases.new
|
16
21
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
if args.first.nil? || args.first == Confinicky::Arguments::ENVIRONMENT
|
23
|
+
puts exports.to_table unless exports.to_table.nil?
|
24
|
+
say_ok "Identified #{exports.length} exports in #{exports.path}"
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "" if args.first.nil?
|
28
|
+
|
29
|
+
if args.first.nil? || args.first == Confinicky::Arguments::ALIAS
|
30
|
+
puts aliases.to_table unless aliases.to_table.nil?
|
31
|
+
say_ok "Identified #{aliases.length} aliases in #{aliases.path}"
|
25
32
|
end
|
26
|
-
puts table
|
27
33
|
|
28
|
-
say_ok "Identified #{shell_file.exports.length} exports in #{Confinicky::ShellFile.file_path}"
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
@@ -1,33 +1,47 @@
|
|
1
1
|
command :remove do |c|
|
2
2
|
c.syntax = 'cfy remove'
|
3
|
-
c.summary = 'Removes an environment variable in your configuration
|
3
|
+
c.summary = 'Removes an alias or environment variable in your configuration.'
|
4
4
|
c.description = ''
|
5
|
-
c.example '
|
5
|
+
c.example 'Remove an environment variable', 'cfy remove export MY_VAR'
|
6
|
+
c.example 'Remove an alias', 'cfy remove alias my_alias'
|
6
7
|
|
7
8
|
c.action do |args, options|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
# Abort if not yet setup.
|
11
|
+
if !Confinicky::ConfigurationFile.setup?
|
12
|
+
say_error "Confinicky's configuration is not valid or has not been setup."
|
13
|
+
puts "Try running 'cfy setup'."
|
14
|
+
abort
|
15
|
+
end
|
16
|
+
|
17
|
+
# Abort if missing arguments.
|
18
|
+
if args.length < 2
|
19
|
+
say_error "You must supply an expression such as: `cfy remove export MY_VAR`"
|
11
20
|
abort
|
12
21
|
end
|
13
22
|
|
14
|
-
|
23
|
+
# Use the appropriate command group controller.
|
24
|
+
command, expression = args[0], args[1]
|
25
|
+
command_group = Confinicky::Controllers::Exports.new if command == Confinicky::Arguments::ENVIRONMENT
|
26
|
+
command_group = Confinicky::Controllers::Aliases.new if command == Confinicky::Arguments::ALIAS
|
15
27
|
|
16
|
-
|
17
|
-
if
|
18
|
-
say_error "Your configuration cannot be managed because it currently has duplicate
|
28
|
+
# Abort if duplicate commands have been found.
|
29
|
+
if command_group.duplicates.length > 0
|
30
|
+
say_error "Your configuration cannot be managed because it currently has duplicate statements."
|
19
31
|
puts "You must run 'cfy clean' before you can manage your configuration."
|
20
32
|
abort
|
21
33
|
end
|
22
34
|
|
23
|
-
|
35
|
+
# Set the variable and save changes to disk.
|
36
|
+
if command_group.remove!(expression) and command_group.save!
|
24
37
|
say_ok "Successfully removed '#{args.first}'."
|
25
|
-
puts "Open a new terminal/shell window for
|
26
|
-
shell_file.write!
|
38
|
+
puts "Open a new terminal/shell window for these changes to take affect."
|
27
39
|
else
|
28
|
-
say_error "Could not remove '#{
|
40
|
+
say_error "Could not remove '#{expression}' please double check to ensure you used the appropriate syntax."
|
29
41
|
end
|
42
|
+
|
30
43
|
end
|
44
|
+
|
31
45
|
end
|
32
46
|
|
33
47
|
alias_command :rm, :remove
|
@@ -1,33 +1,44 @@
|
|
1
1
|
command :set do |c|
|
2
2
|
c.syntax = 'cfy set'
|
3
|
-
c.summary = 'Sets an environment variable in your configuration
|
3
|
+
c.summary = 'Sets an alias or environment variable in your configuration.'
|
4
4
|
c.description = ''
|
5
|
-
c.example '
|
5
|
+
c.example 'Set an environment variable', 'cfy set export MY_VAR="some value"'
|
6
|
+
c.example 'Set an environment alias', 'cfy set alias home="cd ~"'
|
6
7
|
|
7
8
|
c.action do |args, options|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
# Abort if not yet setup.
|
11
|
+
if !Confinicky::ConfigurationFile.setup?
|
12
|
+
say_error "Confinicky's configuration is not valid or has not been setup."
|
13
|
+
puts "Try running 'cfy setup'."
|
11
14
|
abort
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
|
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 'cfy clean' before you can manage your configuration."
|
17
|
+
# Abort if missing arguments.
|
18
|
+
if args.length < 2
|
19
|
+
say_error "You must supply an expression such as: `cfy set export MY_VAR=\"some value\"`"
|
20
20
|
abort
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
# Use the appropriate command group controller.
|
24
|
+
command, expression = args[0], args[1]
|
25
|
+
command_group = Confinicky::Controllers::Exports.new if command == Confinicky::Arguments::ENVIRONMENT
|
26
|
+
command_group = Confinicky::Controllers::Aliases.new if command == Confinicky::Arguments::ALIAS
|
27
|
+
|
28
|
+
# Abort if duplicate commands have been found.
|
29
|
+
if command_group.duplicates.length > 0
|
30
|
+
say_error "Your configuration cannot be managed because it currently has duplicate statements."
|
31
|
+
puts "You must run 'cfy clean #{command}' before you can manage your configuration."
|
32
|
+
abort
|
33
|
+
end
|
24
34
|
|
25
|
-
|
26
|
-
|
35
|
+
# Set the variable and save changes to disk.
|
36
|
+
if command_group.set!(expression) and command_group.save!
|
27
37
|
say_ok "Successfully set '#{args.first}'."
|
28
|
-
puts "
|
38
|
+
puts "Open a new terminal/shell window for these changes to take affect."
|
29
39
|
else
|
30
|
-
say_error "Could not set '#{
|
40
|
+
say_error "Could not set '#{expression}' please double check to ensure you used the appropriate syntax."
|
31
41
|
end
|
42
|
+
|
32
43
|
end
|
33
44
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
command :setup do |c|
|
4
|
+
c.syntax = 'cfy setup'
|
5
|
+
c.summary = 'Generates a ".confinicky" configuration YAML doc in your home directory.'
|
6
|
+
c.description = ''
|
7
|
+
c.example 'description', 'cfy setup'
|
8
|
+
|
9
|
+
c.action do |args, options|
|
10
|
+
|
11
|
+
puts Confinicky::ConfigurationFile.table
|
12
|
+
|
13
|
+
{ env: "\nWhat file do you want to store your environment vars in?\n(leave blank to keep current)",
|
14
|
+
aliases: "\nWhat file do you want to store your aliases in?\n(leave blank to keep current)"
|
15
|
+
}.each do |key, question|
|
16
|
+
Confinicky::ConfigurationFile.set_path_for_key(path: ask(question), key: key)
|
17
|
+
say_ok "Using: #{Confinicky::ConfigurationFile.path_for_key(key: key)}"
|
18
|
+
end
|
19
|
+
|
20
|
+
Confinicky::ConfigurationFile.write!
|
21
|
+
|
22
|
+
say_ok "\nWrote the following configuration to:\n#{Confinicky::ConfigurationFile::PATH}"
|
23
|
+
puts Confinicky::ConfigurationFile.table
|
24
|
+
end
|
25
|
+
end
|
data/lib/confinicky/commands.rb
CHANGED
data/lib/confinicky/config.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
module Confinicky
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
##
|
4
|
+
# Paths to dependencies used primarily for configuration.
|
5
|
+
module Paths
|
6
|
+
CONFIG = "#{ENV['HOME']}/.Confinicky"
|
7
|
+
end
|
8
|
+
|
9
|
+
##
|
10
|
+
# Constants representing arguments which can be passed
|
11
|
+
# to the command line interface.
|
12
|
+
module Arguments
|
13
|
+
ENVIRONMENT = "env"
|
14
|
+
ALIAS = "alias"
|
15
|
+
end
|
16
|
+
|
4
17
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Confinicky
|
2
|
+
|
3
|
+
##
|
4
|
+
# A singleton model representing the configuration YAML utilized
|
5
|
+
# by Confinicky.
|
6
|
+
class ConfigurationFile
|
7
|
+
|
8
|
+
SUPPORTED_KEYS = [:aliases, :env]
|
9
|
+
PATH = Confinicky::Paths::CONFIG
|
10
|
+
|
11
|
+
@@configuration = nil
|
12
|
+
|
13
|
+
##
|
14
|
+
# Retrieves the value of the environment variables file path.
|
15
|
+
def self.path_for_key(key: nil)
|
16
|
+
self.raise_if_key_not_supported(key)
|
17
|
+
self.get_configuration[:files][key]
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Set's the aliases file path.
|
22
|
+
def self.set_path_for_key(path: "", key: nil)
|
23
|
+
self.raise_if_key_not_supported(key)
|
24
|
+
self.get_configuration[:files][key] = path if self.valid_path?(path)
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Writes the output to the appropriate YAML file.
|
29
|
+
def self.write!
|
30
|
+
File.open(PATH, 'w') {|f| f.write self.get_configuration.to_yaml }
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Returns a terminal table displaying the current configuration.
|
35
|
+
def self.table
|
36
|
+
Terminal::Table.new(title: "Configuration", headings: ['type', 'path']) do |t|
|
37
|
+
self.get_configuration[:files].each {|k,v| t.add_row [k.to_s,v]}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Returns true if the configuration file exists along with
|
43
|
+
# all specified paths.
|
44
|
+
def self.setup?
|
45
|
+
File.exists?(PATH) &&
|
46
|
+
File.exists?(self.get_configuration[:files][:env]) &&
|
47
|
+
File.exists?(self.get_configuration[:files][:aliases])
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Forces a configuration, primarily for testing purposes.
|
52
|
+
def self.force_config!(configuration)
|
53
|
+
@@configuration = configuration
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
##
|
59
|
+
# Raises an error if a specified key is not supported.
|
60
|
+
def self.raise_if_key_not_supported(key)
|
61
|
+
raise "Unsupported key supplied to configuration: "+key.to_s unless SUPPORTED_KEYS.include?(key)
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Returns false if the path is blank and raises an error if the
|
66
|
+
# supplied path does not point to an existing file.
|
67
|
+
def self.valid_path?(path)
|
68
|
+
if (!path.nil? && path.length > 0)
|
69
|
+
raise "File does not exist at: #{path}" unless File.exists?(path)
|
70
|
+
return true
|
71
|
+
end
|
72
|
+
false
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Lazy loading to retrieve the contents of the configuration file.
|
77
|
+
def self.get_configuration
|
78
|
+
@@configuration || self.load_configuration
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Loads the configuration file or generates a default hash.
|
83
|
+
def self.load_configuration
|
84
|
+
return @@configuration = YAML::load_file(PATH) if File.exists?(PATH)
|
85
|
+
@@configuration = {files: {aliases: "#{ENV['HOME']}/aliases", env: "#{ENV['HOME']}/env"}}
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Confinicky
|
2
|
+
module Controllers
|
3
|
+
|
4
|
+
##
|
5
|
+
# A subclass of the command group controller specifically
|
6
|
+
# for managing alias statements.
|
7
|
+
class Aliases < Commands
|
8
|
+
def initialize
|
9
|
+
super(file_type_key: :aliases)
|
10
|
+
@commands = @shell_file.aliases
|
11
|
+
@table_title = "Aliases"
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Updates the actual shell file on disk.
|
16
|
+
def save!
|
17
|
+
@shell_file.aliases = @commands
|
18
|
+
@shell_file.write!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|