Skip to content

Commit a54bf06

Browse files
author
Gopal Adhikari
committed
Prepare for gem push to rubygems.org
1 parent 034dcfd commit a54bf06

File tree

9 files changed

+127
-55
lines changed

9 files changed

+127
-55
lines changed

README.md

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,85 @@
1-
# Argonaut
1+
# Argonaut CLI
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/argonaut`. To experiment with that code, run `bin/console` for an interactive prompt.
4-
5-
TODO: Delete this and the text above, and describe your gem
3+
Use Argonaut from your command line!
64

75
## Installation
86

9-
Add this line to your application's Gemfile:
10-
117
```ruby
12-
gem 'argonaut'
8+
gem install argonaut-cli
139
```
1410

15-
And then execute:
11+
Create the config file `~/.argonaut.yml` and populate it with the sample config below:
12+
13+
```yaml
14+
# The only required fields for the gem to run are api_token and url_root
1615

17-
$ bundle
16+
api_token: YOUR_TOKEN
17+
url_root: https://theargonaut-api.herokuapp.com
1818

19-
Or install it yourself as:
19+
# Below are the optional settings to customize output
20+
21+
options:
22+
colorize_rows: true
23+
time_format: '%d %b %Y %l:%M %p'
24+
high_contrast_colors: true
25+
```
2026
21-
$ gem install argonaut
27+
Replace `YOUR_TOKEN` in the sample config above with your own token that can be found in the Profile page in the web app.
28+
29+
You can also export environment variables `ARGONAUT_API_TOKEN` and `ARGONAUT_URL_ROOT` with the correct values without needing a config file.
2230

2331
## Usage
2432

25-
TODO: Write usage instructions here
33+
By default, invoking `argonaut` lists all your environment reservations.
34+
35+
**View all registered teams:**
36+
37+
```
38+
argonaut -T
39+
```
40+
41+
**View reservations table on a particular team's environments:**
42+
43+
Using team id
44+
```
45+
argonaut -t 1
46+
```
47+
48+
Using team name
49+
```
50+
argonaut -t EPA
51+
```
52+
53+
**Make a reservation:**
54+
55+
```
56+
argonaut -r pbm1:epamotron
57+
```
58+
59+
**Release when you are done testing in that environment:**
60+
61+
```
62+
argonaut -r pbm1:epamotron
63+
```
64+
**Clear all your reservations at once**
65+
66+
```
67+
argonaut -c
68+
```
69+
70+
Full list of options can be viewed by running `argonaut -h`. If you are using zsh, you can generate shell completion and add it to your `~/.zshrc` like so:
71+
72+
```
73+
echo compdef _gnu_generic argonaut >> ~/.zshrc
74+
```
2675
2776
## Development
2877
2978
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
3079
31-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32-
3380
## Contributing
3481
35-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/argonaut. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
82+
Bug reports and pull requests are welcome on GitHub at https://github.com/qubbit/argonaut-cli/issues. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
3683
3784
3885
## License

argonaut.gemspec

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
# coding: utf-8
2+
23
lib = File.expand_path('../lib', __FILE__)
34
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
45
require 'argonaut/version'
56

67
EMAIL_DOMAIN = 'gmail.com'
78

89
Gem::Specification.new do |spec|
9-
spec.name = "argonaut"
10+
spec.name = "argonaut-cli"
1011
spec.version = Argonaut::VERSION
1112
spec.authors = ["Gopal Adhikari"]
1213
spec.email = ["nullgeo@#{EMAIL_DOMAIN}"]
13-
spec.summary = "Gem to access Argonaut using the command line interface"
14-
spec.homepage = "https://argonaut.herokuapp.com"
14+
spec.summary = "Command line tool for Argonaut"
15+
spec.description = "This gem lets users manipulate argonaut using the command line interface"
16+
spec.homepage = "https://github.com/qubbit/argonaut-cli"
1517
spec.license = "MIT"
18+
spec.post_install_message = %Q{
19+
⚓️ Please follow instructions at #{spec.homepage} to complete the setup.
20+
}
1621

1722
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
1823
# to allow pushing to a single host or delete this section to allow pushing to any host.
1924
if spec.respond_to?(:metadata)
20-
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
25+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
2126
else
2227
raise "RubyGems 2.0 or newer is required to protect against " \
2328
"public gem pushes."
@@ -34,8 +39,8 @@ Gem::Specification.new do |spec|
3439
spec.add_development_dependency "rake", "~> 10.0"
3540
spec.add_development_dependency "rspec", "~> 3.0"
3641
spec.add_development_dependency "pry-byebug", "~> 3.4"
37-
spec.add_development_dependency "webmock", "~> 3.0.1"
42+
spec.add_development_dependency 'webmock', '~> 3.0', '>= 3.0.1'
3843

39-
spec.add_dependency "httparty"
40-
spec.add_dependency "terminal-table"
44+
spec.add_runtime_dependency 'httparty', '~> 0.15.6'
45+
spec.add_runtime_dependency 'terminal-table', '~> 1.8', '>= 1.8.0'
4146
end

bin/argonaut renamed to exe/argonaut

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
44

5-
require 'pry'
65
begin
76
require File.dirname(THIS_FILE) + '/../lib/argonaut'
87
rescue LoadError
@@ -13,7 +12,7 @@ require 'optparse'
1312

1413
# By default show user's reservations if no arguments are supplied
1514
options = { action: 'list_reservations' }
16-
options.merge! Argonaut::Settings.config[:options]
15+
options.merge! Argonaut::Settings.config.fetch(:options, {})
1716

1817
begin
1918
OptionParser.new do |opts|

lib/argonaut.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def self.exec(options)
4141
require 'terminal-table'
4242

4343
def self.format_date_time(json_time)
44-
Time.parse(json_time).strftime(@options.time_format || '%d %b %Y %l:%M %p')
44+
Time.parse(json_time).getlocal.strftime(@options.time_format || '%d %b %Y %l:%M %p')
4545
end
4646

4747
def self.print_teams(teams_hash)
@@ -109,11 +109,17 @@ def self.print_status(status_hash)
109109
puts table
110110
end
111111

112-
@colors = [122, 141, 153, 163, 172, 178, 183, 186, 223]
113-
@high_contrast_colors = [122, 141, 153, 163, 172, 178, 183, 186, 223]
112+
def self.colors
113+
@colors ||= if @options.high_contrast_colors
114+
# high contrast colors are based on solarized: http://ethanschoonover.com/solarized
115+
[136, 166, 160, 125, 61, 33, 37, 64]
116+
else
117+
[122, 141, 153, 163, 172, 178, 183, 186, 223]
118+
end
119+
end
114120

115121
def self.color(index)
116-
@colors[index % @colors.length]
122+
colors[index % colors.length]
117123
end
118124

119125
def self.colorize_row(row, index)

lib/argonaut/constants.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
module Argonaut
22
class Constants
3-
SETTINGS_FILE = "#{Dir.home}/.argonaut.yml"
3+
SETTINGS_FILE = "#{Dir.home}/.argonaut.yml".freeze
4+
PROJECT_GITHUB_URL = 'https://github.com/qubbit/argonaut-cli'.freeze
5+
PROJECT_README = "#{PROJECT_GITHUB_URL}/blob/master/README.md".freeze
6+
NO_CONFIG_ERROR_MESSAGE = 'Could not load settings file ~/.argonaut.yml'.freeze
7+
NO_URL_ROOT_ERROR_MESSAGE = "URL root for Argonaut is not set. Refer to #{PROJECT_README} for instructions on how to set it up.".freeze
8+
NO_API_TOKEN_ERROR_MESSAGE = "API token for Argonaut is not set. Refer to #{PROJECT_README} for instructions on how to set it up.".freeze
49
end
510
end

lib/argonaut/exceptions.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/argonaut/gateway.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require_relative './exceptions'
1+
require_relative './constants'
22
require 'httparty'
33
require 'uri'
44

@@ -7,7 +7,8 @@ class Gateway
77

88
attr_reader :api_token
99
attr_reader :url_root
10-
ERROR_MESSAGE = 'Could not load settings file ~/.argonaut.yml'.freeze
10+
11+
C = Argonaut::Constants
1112

1213
# Initializes the HTTP gateway to connect to argonaut's API endpoint
1314
# The consumer of this API can supply an API token and
@@ -27,6 +28,16 @@ def initialize(api_token:, url_root:)
2728
else
2829
@url_root = url_root
2930
end
31+
32+
if @url_root.nil?
33+
$stderr.puts C::NO_URL_ROOT_ERROR_MESSAGE
34+
exit(2)
35+
end
36+
37+
if @api_token.nil?
38+
$stderr.puts C::NO_API_TOKEN_ERROR_MESSAGE
39+
exit(2)
40+
end
3041
end
3142

3243
def config
@@ -43,16 +54,10 @@ def config
4354
'url_root' => ENV['ARGONAUT_URL_ROOT']
4455
}
4556

46-
if ENV['ARGONAUT_API_TOKEN'].nil?
47-
raise Argonaut::Exceptions::InvalidConfigurationError.new ERROR_MESSAGE
48-
end
49-
50-
if ENV['ARGONAUT_URL_ROOT'].nil?
51-
raise Argonaut::Exceptions::InvalidConfigurationError.new ERROR_MESSAGE
57+
if ENV['ARGONAUT_API_TOKEN'].nil? || ENV['ARGONAUT_URL_ROOT'].nil?
58+
$stderr.puts C::NO_CONFIG_ERROR_MESSAGE
59+
exit(2)
5260
end
53-
rescue Argonaut::Exceptions::InvalidConfigurationError => ice
54-
puts ice.message
55-
exit(2)
5661
end
5762

5863
def url_from_path(path)
@@ -105,7 +110,7 @@ def post(path:, data:)
105110
end
106111

107112
def self.load_config_from_file
108-
YAML.load_file("#{Dir.home}/.argonaut.yml")
113+
YAML.load_file(C::SETTINGS_FILE)
109114
rescue
110115
nil
111116
end

lib/argonaut/settings.rb

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1+
require_relative './constants'
2+
13
module Argonaut
24
class Settings
35
def self.config
46
@config ||= read_config
57
end
68

7-
private_class_method
9+
class << self
810

9-
def self.read_config
10-
YAML.load_file("#{Dir.home}/.argonaut.yml").with_indifferent_access
11-
rescue
12-
{ options: {
13-
colorize_rows: true,
14-
time_format: '%d %b %Y %l:%M %p'
11+
def read_config
12+
deep_symbolize(YAML.load_file(Argonaut::Constants::SETTINGS_FILE))
13+
rescue Errno::ENOENT
14+
{ options: {
15+
colorize_rows: true,
16+
time_format: '%d %b %Y %l:%M %p'
17+
}
1518
}
16-
}
19+
end
20+
21+
def deep_symbolize(obj)
22+
return obj.inject({}){|memo,(k,v)| memo[k.to_sym] = deep_symbolize(v); memo} if obj.is_a? Hash
23+
return obj.inject([]){|memo,v| memo << deep_symbolize(v); memo} if obj.is_a? Array
24+
return obj
25+
end
26+
1727
end
1828
end
1929
end

lib/argonaut/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Argonaut
2-
VERSION = "0.1.0"
2+
VERSION = "0.1.6"
33
end

0 commit comments

Comments
 (0)