habitica_cli 0.1.1 → 1.0.0

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: 92c5d618ede9ee4d3817e32abb337fde64bc9d13
4
- data.tar.gz: ab1bdfaa12419136c94f77d68afc2d58077ea0a9
3
+ metadata.gz: b47aa3252682b4f60c627064a8567c78e67db09b
4
+ data.tar.gz: 1e316b12c7cd6891e401b3003b3776e9e7af8eb7
5
5
  SHA512:
6
- metadata.gz: 37c71354f0d8e5d4c81429d84eab7db25456150906798cf062ef1439751655980de8002d00a7d4554d237d9b5ee7f5ae7a64bef17570ccaf5a69e9e76f90e590
7
- data.tar.gz: ca44d0ea77106904391351f9174f8ffe35c08594993b1d61d7162ddfcba2391e0690770ffeefed0966bf8b15b6411aa8fd6a1874aff54baa6f8ded61ca0009e9
6
+ metadata.gz: 4a6863a0481d6a0638444ef6e46dff00c446c565d376d64fd9d41a4df86c7c638886ee7c536448e617d6af5e675f337b1f0b32ce4e0735a1a89200c5c5efef6b
7
+ data.tar.gz: 353a4a302d88affca9f2d4e355fe9ef4e582f913b28b6e91727a2552d8157a1730e84c507aee4cdc6b8b650ae8a947609937c2eaf2887e4cb98c81851b59446c
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 2.3.0
data/.travis.yml CHANGED
@@ -1,8 +1,9 @@
1
- sudo: required
1
+ sudo: false
2
2
  dist: precise
3
3
  language: ruby
4
4
  rvm:
5
5
  - 2.2.2
6
+ - 2.3.0
6
7
  before_install:
7
8
  - gem update bundler
8
9
  notifications:
data/README.md CHANGED
@@ -13,6 +13,10 @@ The cli needs your habitica user id and api key. You can configure these via the
13
13
 
14
14
  - Setting/Exporting `HABIT_USER` and `HABIT_KEY` in your environment
15
15
  - Using the `--habit-user` and `--habit-key` flags e.g. `habitica list --habit-user='user-id' --habit-key='user-api-key'`
16
+ - Creating a YAML file with `habit_user: <your user id>` and `habit_key: <your key>` at:
17
+ - osx: `~/Library/Preferencs/habitica_cli-ruby/config.yml`
18
+ - nix: `~/.config/habitica_cli-ruby/config.yml`
19
+ - windows: `~\AppData\Local\Config\habitica_cli-ruby\config.yml`
16
20
 
17
21
  ```shell
18
22
  habitica <command> <action>
data/habitica-cli.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'faraday', '~> 0.9.2'
22
22
  spec.add_dependency 'faraday_middleware', '~> 0.10.0'
23
23
  spec.add_dependency 'thor', '~> 0.19.1'
24
+ spec.add_dependency 'kefir', '~> 1.0.1'
24
25
 
25
26
  spec.add_development_dependency 'bundler', '~> 1.7'
26
27
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -0,0 +1,40 @@
1
+ module HabiticaCli
2
+ # Handles basic configuration parsing
3
+ # and interacts with Kefir for config storage
4
+ class Config
5
+ def initialize(cli_options)
6
+ @options = cli_options
7
+ @config = Kefir.config('habitica_cli')
8
+ end
9
+
10
+ def user_and_api_key
11
+ config = Kefir.config('habitica_cli')
12
+ habit_user, habit_key = @options.values_at(:habit_user, :habit_key)
13
+
14
+ if blank?(habit_user) || blank?(habit_key)
15
+ habit_user = config.get('habit_user')
16
+ habit_key = config.get('habit_key')
17
+ end
18
+
19
+ [habit_user, habit_key]
20
+ end
21
+
22
+ def usage
23
+ <<-ERR
24
+ **Error**: You must provide a habit user and api key
25
+ Do this via:
26
+ - adding `habit_user` and `habit_key` to #{@config.path}
27
+ - setting HABIT_USER and HABIT_KEY in your shell
28
+ - passing --habit_user --habit_key
29
+ ERR
30
+ end
31
+
32
+ private
33
+
34
+ def blank?(obj)
35
+ # rubocop:disable Style/DoubleNegation
36
+ obj.respond_to?(:empty?) ? !!obj.empty? : !obj
37
+ # rubocop:enable Style/DoubleNegation
38
+ end
39
+ end
40
+ end
@@ -1,19 +1,19 @@
1
- require 'ostruct'
2
-
3
1
  module HabiticaCli
4
2
  # At the moment this holds _all_ tasks
5
3
  # until we can figure out a better way to split
6
4
  # out top level tasks into individual files
7
- # (thor's DSL makes that a little bit of a chore at the moment)
5
+ # (thor's DSL makes that a little bit of a chore)
8
6
  class Main < Thor
9
- class_option :habit_user, hide: true, default: ENV['HABIT_USER']
10
- class_option :habit_key, hide: true, default: ENV['HABIT_KEY']
7
+ # rubocop:disable Metrics/LineLength
8
+ class_option :habit_user, hide: true, aliases: '--habit-user', default: ENV['HABIT_USER']
9
+ class_option :habit_key, hide: true, aliases: '--habit-key', default: ENV['HABIT_KEY']
10
+ # rubocop:enable Metrics/LineLength
11
11
 
12
12
  def initialize(*args)
13
13
  super(*args)
14
- @api = api
15
14
  @cache = cache
16
15
  @options = options
16
+ @api = configure_api
17
17
  end
18
18
 
19
19
  # TODO: consider using this inside display instead of select
@@ -53,17 +53,21 @@ module HabiticaCli
53
53
  )
54
54
  end
55
55
 
56
- def cache
57
- @cache ||= Cache.new
58
- end
56
+ def configure_api
57
+ config = Config.new(@options)
58
+ user, key = config.user_and_api_key
59
59
 
60
- def api
61
- user = options[:habit_user]
62
- key = options[:habit_key]
63
- if user.empty? || key.empty?
64
- fail "You must provide a habit user and api key \n\n do this via (HABIT_USER and HABIT_KEY) or the --habit_user --habit_key" # rubocop:disable Metrics/LineLength
60
+ if user.nil? || key.nil?
61
+ help
62
+ puts config.usage
63
+ exit 1
65
64
  end
66
- Api.new(user, key)
65
+
66
+ @api = Api.new(user, key)
67
+ end
68
+
69
+ def cache
70
+ @cache ||= Cache.new
67
71
  end
68
72
  end
69
73
  end
@@ -1,3 +1,3 @@
1
1
  module HabiticaCli
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
data/lib/habitica_cli.rb CHANGED
@@ -1,8 +1,12 @@
1
1
  require 'thor'
2
+ require 'ostruct'
2
3
  require 'pstore'
4
+ require 'ostruct'
5
+ require 'kefir'
3
6
  require 'faraday'
4
7
  require 'faraday_middleware'
5
8
  require 'habitica_cli/version'
9
+ require 'habitica_cli/config'
6
10
  require 'habitica_cli/main'
7
11
  require 'habitica_cli/api'
8
12
  require 'habitica_cli/commands/shared'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: habitica_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Tomlin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-02 00:00:00.000000000 Z
11
+ date: 2016-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: kefir
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +166,7 @@ extra_rdoc_files: []
152
166
  files:
153
167
  - ".gitignore"
154
168
  - ".rspec"
169
+ - ".rubocop.yml"
155
170
  - ".ruby-version"
156
171
  - ".travis.yml"
157
172
  - Gemfile
@@ -169,6 +184,7 @@ files:
169
184
  - lib/habitica_cli/commands/list.rb
170
185
  - lib/habitica_cli/commands/shared.rb
171
186
  - lib/habitica_cli/commands/status.rb
187
+ - lib/habitica_cli/config.rb
172
188
  - lib/habitica_cli/constants.rb
173
189
  - lib/habitica_cli/main.rb
174
190
  - lib/habitica_cli/version.rb
@@ -197,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
213
  version: '0'
198
214
  requirements: []
199
215
  rubyforge_project:
200
- rubygems_version: 2.4.5
216
+ rubygems_version: 2.6.7
201
217
  signing_key:
202
218
  specification_version: 4
203
219
  summary: A minimal CLI for habitica