toolshed 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +11 -0
  4. data/.toolshedrc.sample +32 -0
  5. data/README.md +159 -2
  6. data/Rakefile +3 -3
  7. data/bin/toolshed +6 -1
  8. data/lib/toolshed.rb +38 -28
  9. data/lib/toolshed/base.rb +33 -11
  10. data/lib/toolshed/cli.rb +30 -38
  11. data/lib/toolshed/client.rb +87 -293
  12. data/lib/toolshed/commands/base.rb +65 -23
  13. data/lib/toolshed/commands/checkout_branch.rb +15 -2
  14. data/lib/toolshed/commands/create_branch.rb +34 -29
  15. data/lib/toolshed/commands/create_pivotal_tracker_note.rb +9 -3
  16. data/lib/toolshed/commands/create_pull_request.rb +115 -68
  17. data/lib/toolshed/commands/create_ticket_comment.rb +17 -1
  18. data/lib/toolshed/commands/delete_branch.rb +34 -3
  19. data/lib/toolshed/commands/get_daily_time_update.rb +20 -3
  20. data/lib/toolshed/commands/list_branches.rb +16 -5
  21. data/lib/toolshed/commands/push_branch.rb +28 -9
  22. data/lib/toolshed/commands/rename_branch.rb +29 -0
  23. data/lib/toolshed/commands/ssh.rb +44 -3
  24. data/lib/toolshed/commands/ticket_information.rb +30 -4
  25. data/lib/toolshed/commands/update_pivotal_tracker_story_status.rb +9 -3
  26. data/lib/toolshed/commands/update_ticket_status.rb +8 -2
  27. data/lib/toolshed/entry_point.rb +89 -0
  28. data/lib/toolshed/git.rb +59 -0
  29. data/lib/toolshed/git/branch.rb +224 -0
  30. data/lib/toolshed/git/github.rb +45 -57
  31. data/lib/toolshed/git/validator.rb +14 -0
  32. data/lib/toolshed/logger.rb +46 -0
  33. data/lib/toolshed/password.rb +11 -6
  34. data/lib/toolshed/server_administration/ssh.rb +4 -2
  35. data/lib/toolshed/ticket_tracking/jira.rb +8 -6
  36. data/lib/toolshed/ticket_tracking/pivotal_tracker.rb +8 -6
  37. data/lib/toolshed/time_tracking/harvest.rb +8 -14
  38. data/lib/toolshed/version.rb +25 -1
  39. data/test/commands/checkout_branch_test.rb +11 -7
  40. data/test/commands/create_branch_test.rb +29 -24
  41. data/test/commands/create_pull_request_test.rb +39 -31
  42. data/test/commands/delete_branch_test.rb +35 -25
  43. data/test/commands/get_daily_time_update_test.rb +8 -8
  44. data/test/commands/push_branch_test.rb +27 -15
  45. data/test/commands/rename_branch_test.rb +59 -0
  46. data/test/git/git_helper.rb +5 -5
  47. data/test/git/git_test.rb +36 -31
  48. data/test/git/github_test.rb +9 -46
  49. data/test/helper.rb +11 -11
  50. data/test/server_administration/ssh_test.rb +1 -0
  51. data/test/ticket_tracking/jira_test.rb +18 -16
  52. data/test/time_tracking/harvest_test.rb +8 -6
  53. data/toolshed.gemspec +23 -20
  54. metadata +95 -46
  55. data/bin/toolshed.rb +0 -261
  56. data/lib/toolshed/git/git.rb +0 -119
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bdfea21a3da3ced44701c4030023a41dffd6f24
4
- data.tar.gz: 0e1abc6ed334b5e07390c356242f7e9de3033f54
3
+ metadata.gz: 8a8dfde43412cec6304d3bc7b42485ea14d225c5
4
+ data.tar.gz: 52bbbc59f4384c7ead365df2a4aed53d3f486521
5
5
  SHA512:
6
- metadata.gz: 669886428374a6dfe17cbdfecf5e06b51594cc31d913bc92c526c797b1e8611cfb5fab7ac4bf1e10a6079e7e17d0dd758441679deff0f19f2175cfca74152da8
7
- data.tar.gz: d1876a1cd4ee6d45347210254f206ee1ea12fece621139195c43170b006a0ca0c9d936225d0d2e00f11a751ccd325c1be08a281fd4abcbbdd6b4b6b5301a9c2c
6
+ metadata.gz: 6ddf6b5dcce569a0bc312f8a266b70cbc5d79be95ea318d7fadded6036b99143d394fcab632fc7d8c7c156cf324677d28de154fa56edab22308f91ddf79efbbc
7
+ data.tar.gz: 50c8a2c080727e008ab404f5b03d34481c9cc9cf892cd5cf89f24f42e608f9f772f2393af4f0c315e8182e34b76923a6641b9e5aa4801a229d02e75c66255d44
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ logs
19
+ .toolshedrc
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'test/**/*'
4
+ Metrics/LineLength:
5
+ Max: 90
6
+ Metrics/MethodLength:
7
+ CountComments: false # count full line comments?
8
+ Max: 15
9
+ Style/IndentationConsistency:
10
+ Description: 'Keep indentation straight.'
11
+ Enabled: false
@@ -0,0 +1,32 @@
1
+ ---
2
+ # Command line tool for toolshed. More information about toolshed can be found at https://github.com/wallerjake/toolshed
3
+
4
+ # Before using this tool you should create a file called .toolshedrc in your projects directory or home directory. This is read as a yaml file so format it as you would a yaml file.
5
+ # If added to the projects directory settings will be applied to that specific project. If applied to your home directory all projects under home will get those settings. It will take the first .toolshedrc file it finds so you can override the home directory global one when needed.
6
+
7
+ # log_path: ~/toolshed/logs
8
+
9
+ # ticket_tracking_tool: 'pivotal_tracker' (required)
10
+ # pivotal_tracker_username: [pivotal_tracker_username] (optional)
11
+ # pivotal_tracker_password: [pivotal_tracker_password] (optional)
12
+ # default_pivotal_tracker_project_id: [project_id] (optional)
13
+ # ticket_status_for_complete: [status] (required (only if using pull requests)) example: "Code Review"
14
+
15
+ # github_username: [github_username] (optional)
16
+ # github_password: [github_password] (optional)
17
+ # github_token: [github_token] (optional) - create the token if your account require two factor you can disable token or enable through Github. See https://github.com/settings/tokens/new for details.
18
+ # git_tool: github (optional default `github`)
19
+ # use_git_submodules: false (optional default `false`)
20
+ # pull_from_remote_name: [pull_from_remote_name] (required)
21
+ # pull_from_repository_user: [pull_from_repository_username] (required)
22
+ # pull_from_repository_name: [pull_from_repository_name] (required)
23
+ # push_to_repository_user: [push_to_repository_user] (required)
24
+ # push_to_repository_name: [push_to_repository_name] (required)
25
+ # push_to_remote_name: [push_to_remote_name] (required)
26
+ # default_pull_request_title_format: [id] - [summary] (optional)
27
+
28
+ # time_tracking_username: [username] (optional)
29
+ # time_tracking_password: [password] (optional)
30
+ # time_tracking_owner: [owner] (optional)
31
+ # time_tracking_default_project_id: [project_id] (optional)
32
+ # time_tracking_tool: [tool] (required unless you are not going to be doing time tracking)
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # Toolshed
5
5
 
6
- Toolshed is a utility gem. The purpose of toolshed is to make small to complex command line tasks easier. This includes tasks related to Git like creating a pull request or creating a branch. It also includes tasks like ticket tracking. Currently only a limited set of products is supported but this can be expanded over time as needed.
6
+ Toolshed was made to make every day tasks for a developer easier and faster. It gives yout the ability to configure your environment with settings and then run tasks with one command. For example creating a pull request can require you to go up to Github. Click on create pull request. Select which branch you are creating the pull request for. Put in a title and a description. Then hit create pull request. Also Possibly needing to copy the pull request URL over the ticket it's related to. This can be a time consuming process. With Toolshed you can automated this process and get it down to one command for all of your tickets. If it does not do everything you disire it's easy to extend what is already there and add your own ticket tracking system in. Pull requests are always welcome for adding a new system in.
7
7
 
8
8
  ## Installation
9
9
 
@@ -21,7 +21,164 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- After installing the gem run toolshed from the command line for help menu. It will list the available commands.
24
+ After installing the gem run toolshed from the command line for help menu.
25
+
26
+ ### .toolshedrc
27
+
28
+ The .toolshedrc file is the configuration file for toolshed. This file shall never be committed to version control as you are storing password and other secure data inside of it. The purpose of this file is to store configuration per project or globally. You can store this file in your projects directory or store it in any below directories. For example it could be stored at /home/sample/.toolshedrc for a global configuration. Otherwise it can be stored at /home/sample/projects/sample_project/.toolshedrc for configuration specific to that project. Once it finds a configuration file it will no longer look down the chain. So if you use a project specific .toolshedrc file that is the only configuration file it will look at.
29
+
30
+ #### Options
31
+
32
+ * Required
33
+ * ticket_tracking_tool: github
34
+ * Options: github, jira and pivital_tracker
35
+ * pull_from_remote_name: origin
36
+ * This is where pulling will come from. This is the name you call the remote locally. By default of course it's origin but you can change this.
37
+ * pull_from_repository_user: origin
38
+ * This is the repository name you are pulling from. By default it's called origin.
39
+ * pull_from_repository_name: origin
40
+ * This is the repository name you are pulling from. By default it's called origin.
41
+ * push_to_repository_name: origin
42
+ * This is where pushing will come from. This is the name you call the remote locally. By default of course it's origin but you can change this.
43
+ * push_to_repository_user: origin
44
+ * This is the repository name you are pushing from. By default it's called origin.
45
+ * push_to_remote_name: sample
46
+ * This is the repository name you are pushing from. By default it's called origin.
47
+
48
+ * Optional
49
+ * git_tool: github
50
+ * This is not required but should be provided if using a different tool than Github.
51
+ * github_username: sample_user
52
+ * github_password: sample_password
53
+ * github_token: token_123
54
+ * Create the token if your account require's two factor authentication. You can disable this token or enable it through Github. See https://github.com/settings/tokens/new for details.
55
+ * use_git_submodules: false
56
+ * If you are using Git submodules you may want to turn this option on. By default it's off and not in use.
57
+ * default_pull_request_title_format: [id] - [title]
58
+ * If you want to provide formatting for the pull request title. The default is just to provide the title of the ticket. But you can add this line to format it to include other fields like id. You will need to figure out what the ticket system calls it. For example Pivital Tracker may call it a story_name while Jira may call it a title.
59
+ * pivotal_tracker_username: sample_user
60
+ * pivotal_tracker_password: sample_password
61
+ * default_pivotal_tracker_project_id: 123
62
+ * If no project_id is pass in on commands this will be used by default.
63
+ * ticket_status_for_complete: 'Complete'
64
+ * This is only used when creating a pull request. This will allow the tool to flip the status of a ticket to the next stage. Allows you to automate creating a pull request.
65
+ * time_tracking_username: sample_username
66
+ * If you are using a time tracking system you can use this to set it up. Currently only Harvest is supported.
67
+ * time_tracking_password: sample_password
68
+ * Same as time_tracking_username just for the password field.
69
+ * time_tracking_owner: owner_name
70
+ * Some time tracking systems require an owner to be set. This is probably the company name if using Harvest.
71
+ * time_tracking_default_project_id: 123
72
+ * If the time tracking system has project_ids you can set the default here.
73
+ * time_tracking_tool: harvest
74
+ * Options: harvest
75
+ * Additional time tracking tools could be supported in the future.
76
+ * home_server_password: "sample1234"
77
+ * You can provide a name for reference when using the SSH command.
78
+ * Example: toolshed ssh --user="sample" --host="localhost" --commands="sudo apt-get update;sudo apt-get dist-upgrade;" --password="home_server_password" --sudo-password="home_server_password"
79
+ * This command will allow you to automate updates on an Ubuntu server. This should really only be used for small commands that do not require a lot of logic.
80
+
81
+ ### Available Commands
82
+
83
+ * **help**
84
+ * Commands that are available and what the commands do.
85
+ * **create_pull_request**
86
+ * Give's the ability to create a pull request. Currently only Github is supported at this time.
87
+ * Options
88
+ * **--tool** "github"
89
+ * You can provide the tool you are creating the pull request for. Currently only Github is available but other tools could be added in the future.
90
+ * **--ticket-system** "pivotal_tracker"
91
+ * The ticket system you are using. This can be provided to automatically put the pull request URI into the ticket provided.
92
+ * **Supports**
93
+ * pivotal_tracker
94
+ * jira
95
+ * **--use-defaults** "true"
96
+ * If provided it will just select defaults for each step instead of requiring a prompt for you to input the values.
97
+ * **--title** "Title of pull request"
98
+ * If provided it will not prompt you for the title of the pull request but instead use this value.
99
+ * **--body** "Body of pull request"
100
+ * If provided it will not prompt you for the body of the pull request but instead use this value.
101
+ * **ticket_information**
102
+ * Get the ticket information
103
+ * Options
104
+ * **--use-defaults** "true|false"
105
+ * If you want to use defaults ticket_id is taken from branch_name otherwise configuration is used
106
+ * **--clipboard** "true|false"
107
+ * Copy the output to the system clipboard (Mac OSx) tested
108
+ * **--field** "field_name"
109
+ * The field you want to either output or copy to the clipboard
110
+ * **--formatted-string** "{name} - {url}"
111
+ * Pass a formatted string in ticket name and url in this case and it will return that string replaced by the actual value
112
+ * **create_pivotal_tracker_note**
113
+ * create a note for a specific PivotalTracker story based on project_id and story_id
114
+ * **update_pivotal_tracker_story_status**
115
+ * Update the status of PivotalTracker story
116
+ * **create_branch**
117
+ * Create a branch default (git) and push it to your local repository
118
+ * Options
119
+ * **--branch-name** "123_test"
120
+ * The branch name. The standard is [ticket_id]_description
121
+ * **--branch-from** "master"
122
+ * What branch do you want to branch from
123
+ * **checkout_branch**
124
+ * Checkout a branch [default git] and update the submodules if true
125
+ * Options
126
+ * **--branch-name** "123"
127
+ * Branch name or part of the branch name you want to checkout
128
+ * **push_branch**
129
+ * Push your current working branch to your own repository
130
+ * Options
131
+ * **--force**
132
+ * Push your current working branch up with --force after
133
+ * **--branch-name** "another"
134
+ * Push this specific branch up instead of your current working branch
135
+ * **get_daily_time_update**
136
+ * Get a daily update from your time tracking tool currently *harvest* is supported
137
+ * Options
138
+ * **--format** "html|text"
139
+ * Format you want. If you want html it will open an html page in your broswer otherwise puts out plain text
140
+ * **--use-defaults** "true|false"
141
+ * If you want to use your default project_id instead of entering it
142
+ * **--project-id** "1234"
143
+ * If you want to use a project id other than your defaults.
144
+ * **list_branches**
145
+ * List branches for your remote repository.
146
+ * Options
147
+ * **--repository-name** "depot"
148
+ * The repository name you want to list branches for. If it's not passed pull_from_repository_name is used.
149
+ * **delete_branch**
150
+ * Delete a branch both locally and remote.
151
+ * Options
152
+ * **--branch-name** "134_mybranch" | "134"
153
+ * Either the full branch name or some unique string in the branch i.e. ticket id
154
+ * **create_ticket_comment**
155
+ * Add a comment to a specific ticket.
156
+ * **--use-defaults** "true"
157
+ * Use the defaults instead of getting prompts. If you don't want to supply project name
158
+ * **update_ticket_status**
159
+ * Update a specific tickets status.
160
+ * **ssh**
161
+ * Options
162
+ * **--use-sudo** "true|false"
163
+ * If you want the command to run under sudo i.e. sudo ssh ..
164
+ * **--host** "ip_address"
165
+ * The host you want to connect to
166
+ * **--connection-string-options** "-p 4000"
167
+ * A string of options that will be added onto the command
168
+ * **--commands 'command1;command2'**
169
+ * A list of commands either a string array "["command1", "command2"]" or "command1;command2" or put string into toolshedrc file and call it "main_server_commands"
170
+ * **--password "password1"**
171
+ * The password you are using to login to the server
172
+ * **--prompt-for-password "true|false"**
173
+ * If you want to be more secure and just prompt for passwords
174
+ * **--user "username"**
175
+ * The user you want to connect with
176
+ * **--keys "path/to/file"**
177
+ * IdentityFile you want to use for authentication if passed no password will be asked
178
+ * **--sudo-password "password1"**
179
+ * If you need to use sudo provide a sudo password this can be taken from toolshedrc file also
180
+ * **--verbose-output "true|flase"**
181
+ * If you want to see commands being ran and other verbose output set this flag to true
25
182
 
26
183
  ## Contributing
27
184
 
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
- require File.expand_path(File.dirname(__FILE__)) + "/test/config"
4
+ require File.expand_path(File.dirname(__FILE__)) + '/test/config'
5
5
 
6
6
  Rake::TestTask.new do |t|
7
7
  t.libs << 'test'
8
8
  t.test_files = FileList['test/**/*_test.rb', 'test/*_test.rb']
9
9
  end
10
10
 
11
- desc "Run tests"
11
+ desc 'Run tests'
12
12
  task default: :test
data/bin/toolshed CHANGED
@@ -7,5 +7,10 @@ begin
7
7
  rescue LoadError
8
8
  end
9
9
 
10
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
11
+
10
12
  require 'rake'
11
- require File.dirname(__FILE__) + '/toolshed'
13
+ require 'toolshed/entry_point'
14
+ require 'awesome_print'
15
+
16
+ EntryPoint.instance.execute
data/lib/toolshed.rb CHANGED
@@ -1,37 +1,47 @@
1
- require "toolshed/version"
1
+ require 'toolshed/base'
2
+ require 'toolshed/client'
3
+ require 'toolshed/error'
4
+ require 'toolshed/logger'
5
+ require 'toolshed/version'
6
+
2
7
  require 'httparty'
3
- require 'pivotal-tracker'
4
- require 'jira'
5
- require 'harvested'
6
- require 'veto'
7
8
  require 'launchy'
8
9
  require 'clipboard'
10
+ require 'fileutils'
9
11
 
12
+ # Helper methods for toolshed
10
13
  module Toolshed
11
14
  BLANK_REGEX = /\S+/
12
15
 
13
- # Echoes a deprecation warning message.
14
- #
15
- # @param [String] message The message to display.
16
- # @return [void]
17
- #
18
- # @api internal
19
- # @private
20
- def self.deprecate(message = nil)
21
- message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
22
- warn("DEPRECATION WARNING: #{message}")
16
+ class << self
17
+ def add_file_log_source(command_name = '')
18
+ log_path = Toolshed::Client.instance.log_path
19
+ return if log_path.nil? || log_path.empty?
20
+
21
+ FileUtils.mkdir_p(log_path)
22
+ command_name_string = '_'
23
+ command_name_string = "_#{command_name}_" unless command_name.nil? || command_name.empty? # rubocop:disable Metrics/LineLength
24
+ file_name = "toolshed#{command_name_string}#{Time.now.utc.strftime('%Y%m%d%H%M%S%L')}" # rubocop:disable Metrics/LineLength
25
+ file = "#{log_path}/#{file_name}"
26
+ FileUtils.touch(file)
27
+ logger.add_log_source(file)
28
+ end
29
+
30
+ def deprecate(message = nil)
31
+ message ||= 'You are using deprecated behavior which will be removed from the next major or minor release.' # rubocop:disable Metrics/LineLength
32
+ warn("DEPRECATION WARNING: #{message}")
33
+ end
34
+
35
+ def die(message = '', exit_code = -1)
36
+ logger.fatal message unless message.nil? || message.empty?
37
+ Kernel.exit(exit_code)
38
+ end
39
+
40
+ def logger
41
+ @logger ||= begin
42
+ Toolshed::Logger.create(log_sources: [STDOUT])
43
+ Toolshed::Logger.instance
44
+ end
45
+ end
23
46
  end
24
47
  end
25
-
26
- require 'toolshed/base'
27
- require 'toolshed/client'
28
- require 'toolshed/git/git'
29
- require 'toolshed/git/github'
30
- require 'toolshed/ticket_tracking/ticket_tracking'
31
- require 'toolshed/ticket_tracking/pivotal_tracker'
32
- require 'toolshed/ticket_tracking/jira'
33
- require 'toolshed/time_tracking/time_tracking'
34
- require 'toolshed/time_tracking/harvest'
35
- require 'toolshed/error'
36
- require 'toolshed/password'
37
- require 'toolshed/server_administration/ssh'
data/lib/toolshed/base.rb CHANGED
@@ -1,17 +1,39 @@
1
+ require 'open3'
2
+ require 'timeout'
3
+
1
4
  module Toolshed
5
+ # Base class for toolshed responsible for methods used all over.
2
6
  class Base
3
- def self.wait_for_command(command, seconds=10)
4
- begin
5
- Timeout::timeout(seconds) {
6
- until (system(command))
7
- sleep 1
7
+ def initialize
8
+ end
9
+
10
+ def self.wait_for_command(command, seconds = 10) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/LineLength
11
+ result = {}
12
+ Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
13
+ begin
14
+ Timeout.timeout(seconds) do
15
+ stdin.close # make sure the subprocess is done
16
+
17
+ a_stdout = []
18
+ while line = stdout.gets
19
+ a_stdout << line
20
+ end
21
+ a_stderr = []
22
+ while line = stderr.gets
23
+ a_stderr << line
24
+ end
25
+
26
+ all = a_stdout + a_stderr
27
+ exit_status = wait_thr.value # Process::Status object returned.
28
+ result.merge!(stdout: a_stdout, stderr: a_stderr, all: all, process_status: exit_status) # rubocop:disable Metrics/LineLength
8
29
  end
9
- return
10
- }
11
- rescue Timeout::Error => e
12
- puts "Unable to execute command after #{seconds} seconds"
13
- return
30
+ rescue Timeout::Error
31
+ Process.kill('KILL', wait_thr.pid)
32
+ Toolshed.logger.fatal "Unable to perform the '#{command}' command in the allowed amount of time of #{seconds} seconds. Exiting." # rubocop:disable Metrics/LineLength
33
+ Toolshed.die
34
+ end
14
35
  end
36
+ result
15
37
  end
16
38
  end
17
39
  end
@@ -19,6 +41,6 @@ end
19
41
  String.class_eval do
20
42
  def camel_case
21
43
  return self if self !~ /_/ && self =~ /[A-Z]+.*/
22
- split('_').map{|e| e.capitalize}.join
44
+ split('_').map(&:capitalize).join
23
45
  end
24
46
  end
data/lib/toolshed/cli.rb CHANGED
@@ -1,56 +1,48 @@
1
+ require 'toolshed'
2
+
1
3
  module Toolshed
4
+ # Command not found
2
5
  class CommandNotFound < RuntimeError
3
6
  end
4
7
 
8
+ # CLI is responsible for executing the initial command
5
9
  class CLI
6
- def execute(command_name, args, options={})
7
- Toolshed::Client.load_credentials_if_necessary
8
- command = commands[command_name]
10
+ def execute(command_name, args, options = {})
11
+ load_config(command_name)
12
+ command = send(command_name)
9
13
  if command
10
14
  begin
11
15
  command.new.execute(args, options)
12
16
  rescue Toolshed::Error => e
13
- puts "An error occurred: #{e.message}"
17
+ Toolshed.logger.fatal "An error occurred: #{e.message}"
14
18
  rescue RuntimeError => e
15
- puts "An error occurred: #{e.message}"
19
+ Toolshed.logger.fatal "An error occurred: #{e.message}"
16
20
  end
17
21
  else
18
- raise CommandNotFound, "Unknown command: #{command_name}"
22
+ fail CommandNotFound, "Unknown command: #{command_name}"
19
23
  end
20
24
  end
21
25
 
22
- def commands
23
- {
24
- 'create_pull_request' => Toolshed::Commands::CreatePullRequest,
25
- 'create_pivotal_tracker_note' => Toolshed::Commands::CreatePivotalTrackerNote,
26
- 'ticket_information' => Toolshed::Commands::TicketInformation,
27
- 'update_pivotal_tracker_story_status' => Toolshed::Commands::UpdatePivotalTrackerStoryStatus,
28
- 'create_branch' => Toolshed::Commands::CreateBranch,
29
- 'checkout_branch' => Toolshed::Commands::CheckoutBranch,
30
- 'push_branch' => Toolshed::Commands::PushBranch,
31
- 'get_daily_time_update' => Toolshed::Commands::GetDailyTimeUpdate,
32
- 'list_branches' => Toolshed::Commands::ListBranches,
33
- 'delete_branch' => Toolshed::Commands::DeleteBranch,
34
- 'create_ticket_comment' => Toolshed::Commands::CreateTicketComment,
35
- 'update_ticket_status' => Toolshed::Commands::UpdateTicketStatus,
36
- 'ssh' => Toolshed::Commands::SSH,
37
- }
26
+ def load_config(command_name)
27
+ Toolshed::Client.load_credentials
28
+ Toolshed.add_file_log_source(command_name)
29
+ Toolshed.logger.info "Credentials loaded from #{File.absolute_path(Toolshed::Client.instance.credentials_loaded_from)}" # rubocop:disable Metrics/LineLength
30
+ rescue => e
31
+ Toolshed.logger.fatal "Error loading your credentials: #{e.message}"
32
+ end
33
+
34
+ def method_missing(method_name)
35
+ require "toolshed/commands/#{method_name}"
36
+ "Toolshed::Commands::#{translate_method_name(method_name)}".split('::').inject(Object) { |o, c| o.const_get c } # rubocop:disable Metrics/LineLength
37
+ rescue NameError => e
38
+ Toolshed.logger.fatal e.message
39
+ Toolshed.die
40
+ end
41
+
42
+ def translate_method_name(name)
43
+ name = name.to_s
44
+ name.upcase! if %w(ssh).include?(name.downcase)
45
+ name.camel_case
38
46
  end
39
47
  end
40
48
  end
41
-
42
- require 'toolshed/commands/base'
43
- require 'toolshed/commands/create_pull_request'
44
- require 'toolshed/commands/create_pivotal_tracker_note'
45
- require 'toolshed/commands/ticket_information'
46
- require 'toolshed/commands/update_pivotal_tracker_story_status'
47
- require 'toolshed/commands/create_branch'
48
- require 'toolshed/commands/checkout_branch'
49
- require 'toolshed/commands/push_branch'
50
- require 'toolshed/commands/get_daily_time_update'
51
- require 'toolshed/commands/get_daily_time_update'
52
- require 'toolshed/commands/list_branches'
53
- require 'toolshed/commands/delete_branch'
54
- require 'toolshed/commands/create_ticket_comment'
55
- require 'toolshed/commands/update_ticket_status'
56
- require 'toolshed/commands/ssh'