codeunion 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3a8dc759f3f6ff3bdc7ff87a232083fce375484
4
- data.tar.gz: 56d65da1ad015b6498cd59037d112affbb57ed95
3
+ metadata.gz: 4974f6eb01104b8573b4e0deaa5639e1086032cc
4
+ data.tar.gz: dbe02e702d20aa4879662b91dfe0b736931d1c45
5
5
  SHA512:
6
- metadata.gz: 681f8d162e0628ecd806e0d146952d94fe119ca0bdf5bf28c88dde69efb3a0d47a070dcbfe569ac352eb873d83fd9057fcdb42530ab492c5d40347ec89ce41ed
7
- data.tar.gz: 4d7a990783baddec49977d75eb516562b1c9800b846d6cee24b7d642c2afd3342a97a26a14c193e48095548aeb596471c551524ffae2a0b071b62f02c5eb1d49
6
+ metadata.gz: efec75d73b5607462b3fda7b39354b96125916273602895ee26178c3de172dfe7f79f699d7a707433969020e7ab167617bc8cff3c70403c9b10016017dda2958
7
+ data.tar.gz: 20861af23710e2f96c2ee2486bab9261f988fe5e7dc4d29478687a01d540779eabb392da261f1925218f74692b7c930e47844fde47eb7e23ac90330e8b950392
data/.rubocop.yml CHANGED
@@ -6,6 +6,10 @@ Style/Documentation:
6
6
  Exclude:
7
7
  - 'lib/codeunion/version.rb'
8
8
 
9
+ Style/FileName:
10
+ Exclude:
11
+ - 'bin/*'
12
+
9
13
  Style/StringLiterals:
10
14
  Enabled: true
11
15
  EnforcedStyle: double_quotes
data/bin/codeunion CHANGED
@@ -8,5 +8,6 @@ bin_file = Pathname.new(__FILE__).realpath
8
8
  # Add the gem's "lib" directory to library path
9
9
  $LOAD_PATH.unshift File.expand_path("../../lib", bin_file)
10
10
 
11
- require "codeunion/cli"
12
- CodeUnion::CLI.start(*ARGV)
11
+ require "codeunion/command/main"
12
+
13
+ CodeUnion::Command::Main.new(*ARGV).run
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ # Resolve the pathname for this executable
5
+ require "pathname"
6
+ bin_file = Pathname.new(__FILE__).realpath
7
+
8
+ # Add the gem's "lib" directory to library path
9
+ $LOAD_PATH.unshift File.expand_path("../../lib", bin_file)
10
+
11
+ require "codeunion/command/config"
12
+
13
+ CodeUnion::Command::Config.new(*ARGV).run
@@ -1,34 +1,7 @@
1
1
  require "codeunion"
2
- require "ptools"
3
2
 
4
3
  module CodeUnion
5
- # This class serves as a simple wrapper around subcommands
6
- class Command
4
+ module Command
7
5
  class CommandNotFound < StandardError; end
8
-
9
- def initialize(command, *args)
10
- @command = command
11
- @args = args
12
- end
13
-
14
- def exist?
15
- File.which(executable_name)
16
- end
17
-
18
- def exec!
19
- if exist?
20
- exec(executable_name, *args)
21
- else
22
- fail CommandNotFound, "Unknown command `#{@command}`."
23
- end
24
- end
25
-
26
- private
27
-
28
- attr_reader :command, :args
29
-
30
- def executable_name
31
- "codeunion-#{command}"
32
- end
33
6
  end
34
7
  end
@@ -0,0 +1,16 @@
1
+ require "codeunion/command"
2
+
3
+ module CodeUnion
4
+ module Command
5
+ # A base class for built-in commands
6
+ class Base
7
+ def initialize(*args)
8
+ @args = args
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :args
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ require "codeunion/command/base"
2
+ require "codeunion/config"
3
+ require "fileutils"
4
+
5
+ module CodeUnion
6
+ module Command
7
+ # The bulit-in `codeunion config` command
8
+ class Config < Base
9
+ CONFIG_DIR = File.join(Dir.home, ".codeunion")
10
+ CONFIG_FILE = File.join(CONFIG_DIR, "config")
11
+
12
+ def run
13
+ ensure_config_exists!
14
+
15
+ case args.length
16
+ when 1
17
+ puts config.get(*args)
18
+ when 2
19
+ config.set(*args)
20
+ end
21
+
22
+ save_config!
23
+ end
24
+
25
+ private
26
+
27
+ def config
28
+ @config ||= CodeUnion::Config.new(YAML.load_file(CONFIG_FILE))
29
+ end
30
+
31
+ def ensure_config_exists!
32
+ FileUtils.mkdir(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
33
+ write_config_data({}) unless File.exist?(CONFIG_FILE)
34
+ end
35
+
36
+ def save_config!
37
+ write_config_data(config)
38
+ end
39
+
40
+ def write_config_data(data)
41
+ File.open(CONFIG_FILE, "w") do |f|
42
+ f.write YAML.dump(Hash(data))
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,35 @@
1
+ require "codeunion/command/base"
2
+ require "ptools"
3
+
4
+ module CodeUnion
5
+ module Command
6
+ # The built-in main `codeunion` command
7
+ class Main < Base
8
+ def run
9
+ if exist?
10
+ exec(executable_name, *command_args)
11
+ else
12
+ fail CommandNotFound, "Unknown command `#{command_name}`."
13
+ end
14
+ end
15
+
16
+ def exist?
17
+ File.which(executable_name)
18
+ end
19
+
20
+ private
21
+
22
+ def command_name
23
+ args.first
24
+ end
25
+
26
+ def command_args
27
+ args.drop(1)
28
+ end
29
+
30
+ def executable_name
31
+ "codeunion-#{command_name}"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ require "yaml"
2
+
3
+ module CodeUnion
4
+ # A class to manage CodeUnion configuration data
5
+ class Config
6
+ def initialize(config_data)
7
+ @config = Hash(config_data.dup)
8
+ @config.default_proc = proc { |h, k| h[k] = {} }
9
+ end
10
+
11
+ def set(dotted_key, value)
12
+ @config = set_dotted(@config, dotted_key, value)
13
+ self
14
+ end
15
+
16
+ def get(dotted_key)
17
+ get_dotted(@config, dotted_key)
18
+ end
19
+
20
+ def to_hash
21
+ @config.dup
22
+ end
23
+
24
+ alias_method :to_h, :to_hash
25
+
26
+ private
27
+
28
+ def set_dotted(config, dotted_key, value)
29
+ return value if dotted_key.nil?
30
+
31
+ key, sub_key = extract_subkey(dotted_key)
32
+
33
+ config.merge(key => set_dotted(config[key], sub_key, value))
34
+ end
35
+
36
+ def get_dotted(config, dotted_key)
37
+ key, sub_key = extract_subkey(dotted_key)
38
+
39
+ if sub_key
40
+ get_dotted(config[key], sub_key)
41
+ else
42
+ config[key]
43
+ end
44
+ end
45
+
46
+ def extract_subkey(dotted_key)
47
+ dotted_key.split(".", 2)
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module CodeUnion
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeunion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Farmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ email:
72
72
  - jesse@codeunion.io
73
73
  executables:
74
74
  - codeunion
75
+ - codeunion-config
75
76
  extensions: []
76
77
  extra_rdoc_files: []
77
78
  files:
@@ -82,10 +83,14 @@ files:
82
83
  - README.md
83
84
  - Rakefile
84
85
  - bin/codeunion
86
+ - bin/codeunion-config
85
87
  - codeunion.gemspec
86
88
  - lib/codeunion.rb
87
- - lib/codeunion/cli.rb
88
89
  - lib/codeunion/command.rb
90
+ - lib/codeunion/command/base.rb
91
+ - lib/codeunion/command/config.rb
92
+ - lib/codeunion/command/main.rb
93
+ - lib/codeunion/config.rb
89
94
  - lib/codeunion/version.rb
90
95
  homepage: http://github.com/codeunion/codeunion-client
91
96
  licenses:
data/lib/codeunion/cli.rb DELETED
@@ -1,13 +0,0 @@
1
- require "codeunion"
2
- require "codeunion/command"
3
-
4
- module CodeUnion
5
- # This class serves as a simple command-line client
6
- class CLI
7
- def self.start(*args)
8
- subcommand = args.shift.strip
9
-
10
- CodeUnion::Command.new(subcommand, *args).exec!
11
- end
12
- end
13
- end