learn-co-dev 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0f77368fce07ccb1eff7f7d92c29dad4d7e460be
4
+ data.tar.gz: e05a87d3260a1a4b4d333a4ed3635b415d0981d0
5
+ SHA512:
6
+ metadata.gz: c534df21c83811c3a97b706fcd95ff3d6de2b8d2d798319e6c77edc528f4803cb4c28182409afaacdadece35ace0f09a5f62652f94f2b7d729bf3ca8d5561da4
7
+ data.tar.gz: 65bfd12b24f6bce1cdff42eca1d6fa331e35102d914dc0905a5ae786bbf99de9d17e991e8b6e6c9e7c5134c765c9afb3a3aa283743b34c7f0eb37dd74aab5ca5
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in learn-co.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014-2015 Flatiron School
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # learn-co
2
+
3
+ The command line interface to Learn.co.
4
+
5
+ ## Installation
6
+
7
+ Install with:
8
+
9
+ ```
10
+ $ gem install learn-co
11
+ ```
12
+
13
+ Alternatively, add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'learn-co'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+ From within a Learn.co lesson directory, run:
26
+
27
+ ```
28
+ $ learn [command]
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/flatiron-labs/learn-co/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/learn-dev ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'learn'
4
+
5
+ NON_PRE_CONFIG_COMMANDS = [
6
+ 'reset', 'whoami', 'directory', 'help', 'version', '--version', '-v', 'doctor', 'new', 'hello', 'lint', 'save'
7
+ ]
8
+
9
+ INTERNET_REQUIRED_COMMANDS = [
10
+ 'whoami', 'doctor', 'directory', 'reset', 'hello'
11
+ ]
12
+
13
+ LEARN_CONFIG_COMMANDS = ['reset', 'whoami', 'directory']
14
+
15
+ if ['-v', '--version'].include?(ARGV.first)
16
+ puts Learn::VERSION
17
+ exit
18
+ end
19
+
20
+ Learn::OptionsSanitizer.new(ARGV).sanitize!
21
+
22
+ # Legacy: leaving this in just in case we do decide to return to our previously
23
+ # extra-defensive auth checking
24
+ # if !(NON_PRE_CONFIG_COMMANDS.include?(ARGV[0]))
25
+ # system('learn-config') unless Learn::InternetConnection.no_internet_connection?
26
+ # end
27
+
28
+ netrc = Learn::NetrcInteractor.new
29
+ netrc.read
30
+ token = netrc.password
31
+
32
+ if !LEARN_CONFIG_COMMANDS.include?(ARGV[0]) && (token.nil? || token == 'machine' || !File.exist?(File.expand_path('~/.learn-config')))
33
+ system('learn-config') unless Learn::InternetConnection.no_internet_connection?
34
+ end
35
+
36
+ if INTERNET_REQUIRED_COMMANDS.include?(ARGV[0])
37
+ Learn::InternetConnection.test_connection
38
+ end
39
+
40
+ Learn::CLI.start(ARGV)
data/learn-co.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'learn/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "learn-co-dev"
8
+ spec.version = Learn::VERSION
9
+ spec.authors = ["Flatiron School"]
10
+ spec.email = ["learn@flatironschool.com"]
11
+ spec.summary = %q{The command line interface to Learn.co.}
12
+ spec.homepage = "https://github.com/learn-co/learn-co"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib", "bin"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "pry"
23
+
24
+ spec.add_runtime_dependency "learn-test", "2.5.0.rc1"
25
+ spec.add_runtime_dependency "learn-config", ">= 1.0.77"
26
+ spec.add_runtime_dependency "learn-open", ">= 1.2.1"
27
+ spec.add_runtime_dependency "learn-submit", "1.3.1"
28
+ spec.add_runtime_dependency "learn-doctor", ">= 1.0.3"
29
+ spec.add_runtime_dependency "learn-generate", ">= 1.0.16"
30
+ spec.add_runtime_dependency "learn-status", ">= 1.0.1"
31
+ spec.add_runtime_dependency "learn-hello", ">= 1.0.1"
32
+ spec.add_runtime_dependency "learn_linter", ">= 1.6.0"
33
+ spec.add_runtime_dependency "netrc", ">= 0.11.0"
34
+ spec.add_runtime_dependency "thor", ">= 0.19.1"
35
+ end
data/lib/learn.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'thor'
2
+
3
+ require 'learn/version'
4
+ require 'learn/internet_connection'
5
+ require 'learn/team_members/parser'
6
+ require 'learn/cli'
7
+ require 'learn/options_sanitizer'
8
+ require 'learn/lab/parser'
9
+ require 'learn/netrc_interactor'
10
+
11
+ module Learn
12
+ end
data/lib/learn/cli.rb ADDED
@@ -0,0 +1,145 @@
1
+ module Learn
2
+ class CLI < Thor
3
+ desc '[test] [options]', "Run a lesson's test suite"
4
+ long_desc <<-LONGDESC
5
+ `learn [test] [options]` will run your lesson's test suite.
6
+
7
+ You can supply the following options when running Jasmine tests:
8
+
9
+ --no-color # Turn off color output
10
+ \x5 -l, --local # Don't push results to Learn
11
+ \x5 -b, --browser # Run tests in browser
12
+ \x5 -o, --out FILE # Specify an output file
13
+ \x5 -s, --skip # Don't run dependency checks
14
+
15
+ You can supply the following options when running Rspec tests:
16
+
17
+ --fail-fast # Stop running rspec test suite on first failed test
18
+ LONGDESC
19
+ def test(*opts)
20
+ system("learn-test #{opts.join(' ')}")
21
+ end
22
+
23
+ desc 'version, -v, --version', 'Display the current version of the Learn gem'
24
+ def version
25
+ puts Learn::VERSION
26
+ end
27
+
28
+ desc 'submit [-m|--message "message"] [-t|--team @username @username2]', 'Submit your completed lesson'
29
+ option :message, required: false, type: :string, aliases: ['m']
30
+ option :team, required: false, type: :string, aliases: ['t']
31
+ long_desc <<-LONGDESC
32
+ `learn submit [-m|--message "message"] [-t|--team @username, @username2]` will submit your lesson to Learn.
33
+
34
+ If you provide the -t|--team flag, specified team memebers will also get credit.
35
+
36
+ It will add your changes, commit them, push to GitHub, and issue a pull request.
37
+ LONGDESC
38
+ def submit(*opts)
39
+ commit_message = if options['team']
40
+ Learn::TeamMembers::Parser.new(ARGV).execute
41
+ else
42
+ options['message']
43
+ end
44
+
45
+ system("learn-submit #{commit_message}")
46
+ end
47
+
48
+ desc "open [lesson-name] [--editor=editor-binary]", "Open your current lesson [or the given lesson] [with your editor]"
49
+ long_desc <<-LONGDESC
50
+ `learn open [lesson-name] [--editor=editor-binary]` will open a Learn lesson locally.
51
+
52
+ If given no lesson name, it will open your current lesson. By default, it will open
53
+ using the editor specified in ~/.learn-config.
54
+
55
+ If the lesson is an iOS lab, it will open in Xcode. If it is a README, it will open the lesson
56
+ in your browser.
57
+ LONGDESC
58
+ option :editor, required: false, type: :string, aliases: ['e']
59
+ def open(*lab_name)
60
+ lab_name = Learn::Lab::Parser.new(lab_name.join(' ')).parse!
61
+ editor = options[:editor]
62
+
63
+ system("learn-open #{lab_name} --editor=#{editor}")
64
+ end
65
+
66
+ desc "next [--editor=editor-binary]", "Open your next lesson [with your editor]"
67
+ option :editor, required: false, type: :string, aliases: ['e']
68
+ def next
69
+ editor = options[:editor]
70
+
71
+ system("learn-open --next --editor=#{editor}")
72
+ end
73
+
74
+ desc 'whoami', 'Display your Learn gem configuration information'
75
+ def whoami
76
+ system('learn-config --whoami')
77
+ end
78
+
79
+ desc 'reset', 'Reset your Learn gem configuration'
80
+ def reset
81
+ system('learn-config --reset')
82
+ end
83
+
84
+ desc 'directory', 'Set your local Learn directory. Defaults to ~/Development/code'
85
+ def directory
86
+ system('learn-config --set-directory')
87
+ end
88
+
89
+ desc 'doctor', 'Check your local environment setup'
90
+ def doctor
91
+ system('learn-doctor')
92
+ end
93
+
94
+ desc 'new lab-name -t|--template template-name', 'Generate a new lesson repo using a Learn.co template', hide: true
95
+ option :template, required: false, type: :string, aliases: ['t']
96
+ option :list, required: false, type: :boolean
97
+ def new(*lab_name)
98
+ has_internet = Learn::InternetConnection.internet_connection?
99
+ template = options[:template]
100
+ list = options[:list]
101
+
102
+ if list
103
+ system("learn-generate --list #{has_internet ? '--internet' : ''}")
104
+ else
105
+ if template && template != 'template'
106
+ system("learn-generate #{template} #{lab_name.join} #{has_internet ? '--internet' : ''}")
107
+ else
108
+ puts "You must specify a template with -t or --template"
109
+ exit
110
+ end
111
+ end
112
+ end
113
+
114
+ desc 'status', 'Get the status of your current lesson'
115
+ def status
116
+ system('learn-status')
117
+ end
118
+
119
+ desc 'hello', 'Verify your connection to Learn.co'
120
+ def hello
121
+ system('learn-hello')
122
+ end
123
+
124
+ desc 'lint', 'Lint a directory for correct content', hide: true
125
+ def lint(dir=nil, quiet=nil)
126
+ if dir && !quiet
127
+ system("learn-lint #{dir}")
128
+ elsif dir && quiet
129
+ system("learn-lint #{dir} #{quiet}")
130
+ elsif !dir && quiet
131
+ system("learn-lint #{quiet}")
132
+ else
133
+ current_dir = Dir.pwd
134
+ system("learn-lint #{current_dir}")
135
+ end
136
+ end
137
+
138
+ desc 'save', 'Save your work and push it to GitHub'
139
+ def save
140
+ if !system('learn-submit --save-only')
141
+ exit 1
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,77 @@
1
+ require 'net/http'
2
+ require 'timeout'
3
+ require 'openssl'
4
+
5
+ module Learn
6
+ class InternetConnection
7
+ attr_accessor :connection
8
+ attr_reader :silent
9
+
10
+ STATUS_URI = URI('https://learn.co/p/gem_status')
11
+ SUCCESS_STATUS = 'this is a boring message to prove you can connect to the internet'
12
+ NO_INTERNET_MESSAGE = "It seems like you aren't connected to the internet. All features of the Learn gem may not work properly. Trying anyway..."
13
+
14
+ def self.no_internet_connection?
15
+ new.no_connection?
16
+ end
17
+
18
+ def self.internet_connection?
19
+ new(silent: true).connection?
20
+ end
21
+
22
+ def self.test_connection
23
+ new
24
+ end
25
+
26
+ def initialize(silent: false)
27
+ @connection = false
28
+ @silent = silent
29
+
30
+ test_connection
31
+ end
32
+
33
+ def test_connection(retries: 3)
34
+ begin
35
+ Timeout::timeout(5) do
36
+ resp = Net::HTTP.get(STATUS_URI)
37
+
38
+ if resp.match(/#{SUCCESS_STATUS}/)
39
+ self.connection = true
40
+ else
41
+ self.connection = false
42
+ puts NO_INTERNET_MESSAGE if !silent
43
+ end
44
+ end
45
+ rescue Timeout::Error
46
+ if retries > 0
47
+ test_connection(retries: retries - 1)
48
+ else
49
+ self.connection = false
50
+ puts NO_INTERNET_MESSAGE if !silent
51
+ end
52
+ rescue SocketError => e
53
+ if e.message.match(/getaddrinfo: nodename nor servname provided/)
54
+ if retries > 0
55
+ test_connection(retries: retries - 1)
56
+ else
57
+ self.connection = false
58
+ puts NO_INTERNET_MESSAGE if !silent
59
+ end
60
+ end
61
+ rescue OpenSSL::SSL::SSLError
62
+ self.connection = false
63
+ puts "It looks like your SSL certificates aren't quite right."
64
+ puts "Please run `rvm osx-ssl-certs update all` and then try again."
65
+ exit
66
+ end
67
+ end
68
+
69
+ def no_connection?
70
+ !connection
71
+ end
72
+
73
+ def connection?
74
+ connection
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,25 @@
1
+ module Learn
2
+ module Lab
3
+ class Parser
4
+ attr_reader :name
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+
10
+ def parse!
11
+ if name.chars.include?(' ')
12
+ slugify_name!
13
+ else
14
+ name.downcase.strip
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def slugify_name!
21
+ name.downcase.gsub(' ', '-').strip
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'netrc'
2
+
3
+ module Learn
4
+ class NetrcInteractor
5
+ attr_reader :login, :password, :netrc
6
+
7
+ def initialize
8
+ ensure_proper_permissions!
9
+ end
10
+
11
+ def read(machine: 'learn-config')
12
+ @netrc = Netrc.read
13
+ @login, @password = netrc[machine]
14
+ end
15
+
16
+ def write(machine: 'learn-config', new_login:, new_password:)
17
+ netrc[machine] = new_login, new_password
18
+ netrc.save
19
+ end
20
+
21
+ def delete!(machine:)
22
+ @netrc = Netrc.read
23
+
24
+ netrc.delete(machine)
25
+ netrc.save
26
+ end
27
+
28
+ private
29
+
30
+ def ensure_proper_permissions!
31
+ system('chmod 0600 ~/.netrc &>/dev/null')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,221 @@
1
+ module Learn
2
+ class OptionsSanitizer
3
+ attr_reader :args
4
+
5
+ SANITIZE_LIST = {
6
+ '-e' => '--editor',
7
+ '-t' => '--template'
8
+ }
9
+
10
+ KNOWN_COMMANDS = [
11
+ 'test',
12
+ 'help',
13
+ 'version',
14
+ '-v',
15
+ '--version',
16
+ 'submit',
17
+ 'open',
18
+ 'reset',
19
+ 'whoami',
20
+ 'directory',
21
+ 'next',
22
+ 'doctor',
23
+ 'new',
24
+ 'status',
25
+ 'lint',
26
+ 'hello',
27
+ 'save'
28
+ ]
29
+
30
+ KNOWN_TEST_FLAGS = [
31
+ '--no-color',
32
+ '-b',
33
+ '--browser',
34
+ '-s',
35
+ '--skip',
36
+ '--keep',
37
+ '--fail-fast'
38
+ ]
39
+
40
+ def initialize(args)
41
+ @args = args
42
+ end
43
+
44
+ def sanitize!
45
+ sanitize_non_test_args!
46
+ sanitize_test_args!
47
+ end
48
+
49
+ private
50
+
51
+ # Sanitization methods
52
+ def sanitize_non_test_args!
53
+ args.map! do |arg|
54
+ SANITIZE_LIST[arg] ? SANITIZE_LIST[arg] : arg
55
+ end
56
+ end
57
+
58
+ def sanitize_test_args!
59
+ if missing_or_unknown_args?
60
+ handle_missing_or_unknown_args
61
+ elsif has_test_command_and_invalid_flag?
62
+ exit_with_invalid_flag
63
+ elsif has_test_command_and_output_flag?
64
+ check_for_output_file(add_test_command: false)
65
+ end
66
+ end
67
+
68
+ # Arg manipulation methods
69
+ def handle_missing_or_unknown_args
70
+ if first_arg_not_a_flag_or_file?
71
+ exit_with_unknown_command
72
+ elsif has_output_flag? || has_format_flag?
73
+ check_for_output_file if has_output_flag?
74
+ check_for_format_type if has_format_flag?
75
+ elsif only_has_flag_arguments?
76
+ add_test_command
77
+ else
78
+ exit_with_cannot_understand
79
+ end
80
+ end
81
+
82
+ def check_for_output_file(add_test_command: true)
83
+ index = args.index('-o') || args.index('--out')
84
+
85
+ if flag_argument_specified?(index)
86
+ initial_arg_index = add_test_command ? 0 : 1
87
+ out_arg = "#{args[index]} #{args[index+1]}"
88
+ delete_flag_args!(index)
89
+
90
+ if only_has_known_test_flags?(initial_arg_index)
91
+ rebuild_args!(flag_arg: out_arg, add_test_command: add_test_command)
92
+ else
93
+ exit_with_unknown_flags
94
+ end
95
+ else
96
+ exit_with_missing_output_file
97
+ end
98
+ end
99
+
100
+ def check_for_format_type(add_test_command: true)
101
+ index = args.index('-f') || args.index('--format')
102
+
103
+ if flag_argument_specified?(index)
104
+ initial_arg_index = add_test_command ? 0 : 1
105
+ format_arg = "#{args[index]} #{args[index+1]}"
106
+ delete_flag_args!(index)
107
+
108
+ if only_has_known_test_flags?(initial_arg_index)
109
+ rebuild_args!(flag_arg: format_arg, add_test_command: add_test_command)
110
+ else
111
+ exit_with_unknown_flags
112
+ end
113
+ else
114
+ exit_with_missing_format_type
115
+ end
116
+ end
117
+
118
+ def delete_flag_args!(index)
119
+ args.delete_at(index+1)
120
+ args.delete_at(index)
121
+ end
122
+
123
+ def rebuild_args!(flag_arg:, add_test_command:)
124
+ args.unshift('test') if add_test_command
125
+ args.push(flag_arg)
126
+ end
127
+
128
+ def add_test_command
129
+ args.unshift('test')
130
+ end
131
+
132
+ # Arg check methods
133
+ def missing_or_unknown_args?
134
+ args.empty? || !KNOWN_COMMANDS.include?(args[0])
135
+ end
136
+
137
+ def first_arg_not_a_flag_or_file?
138
+ args[0] && !args[0].start_with?('-') && first_arg_not_a_file?
139
+ end
140
+
141
+ def first_arg_not_a_file?
142
+ ['/', '.'].none? { |punct| args[0].include?(punct) } && !File.exists?(args[0])
143
+ end
144
+
145
+ def arg_is_a_file?(arg)
146
+ arg && (['/', '.'].any? { |punct| arg.include?(punct) } || File.exists?(arg))
147
+ end
148
+
149
+ def has_output_flag?
150
+ args.any? {|arg| ['-o', '--out'].include?(arg)}
151
+ end
152
+
153
+ def has_format_flag?
154
+ args.any? {|arg| ['-f', '--format'].include?(arg)}
155
+ end
156
+
157
+ def only_has_known_test_flags?(start_index)
158
+ if arg_is_a_file?(args[start_index])
159
+ start_index += 1
160
+ end
161
+
162
+ args[start_index..-1].all? {|arg| KNOWN_TEST_FLAGS.include?(arg)}
163
+ end
164
+
165
+ def flag_argument_specified?(index)
166
+ args[index+1] && !args[index+1].start_with?('-')
167
+ end
168
+
169
+ def only_has_flag_arguments?
170
+ if arg_is_a_file?(args[0])
171
+ args[1..-1].all? {|arg| arg.start_with?('-')}
172
+ else
173
+ args.all? {|arg| arg.start_with?('-')}
174
+ end
175
+ end
176
+
177
+ def has_test_command_and_invalid_flag?
178
+ args[0] == 'test' && args[1] && !args[1].start_with?('-') && !arg_is_a_file?(args[1])
179
+ end
180
+
181
+ def has_test_command_and_output_flag?
182
+ args[0] == 'test' && args.any? {|arg| ['-o', '--out'].include?(arg)}
183
+ end
184
+
185
+ def has_test_command_and_format_flag?
186
+ args[0] == 'test' && args.any? {|arg| ['-f', '--format'].include?(arg)}
187
+ end
188
+
189
+ # Exit methods
190
+ def exit_with_invalid_flag
191
+ puts "Invalid flag: #{args[1]}"
192
+ exit
193
+ end
194
+
195
+ def exit_with_unknown_command
196
+ puts "Unknown command: #{args[0]}. Type `learn help` to see what you can do."
197
+ exit
198
+ end
199
+
200
+ def exit_with_cannot_understand
201
+ puts "Sorry, I can't understand what you're trying to do. Type `learn help` for help."
202
+ exit
203
+ end
204
+
205
+ def exit_with_unknown_flags
206
+ unknown_flags = args.select {|arg| !KNOWN_TEST_FLAGS.include?(arg)}
207
+ puts "Unknown #{unknown_flags.count > 1 ? 'flags' : 'flag'}: #{unknown_flags.join(', ')}"
208
+ exit
209
+ end
210
+
211
+ def exit_with_missing_output_file
212
+ puts "Must specify an output file when using the -o, --out flag."
213
+ exit
214
+ end
215
+
216
+ def exit_with_missing_format_type
217
+ puts "Must specify a format type when using the -f, --format flag."
218
+ exit
219
+ end
220
+ end
221
+ end
@@ -0,0 +1,71 @@
1
+ module Learn
2
+ module TeamMembers
3
+ class Parser
4
+ attr_reader :full_args
5
+ attr_accessor :members_list
6
+
7
+ def initialize(full_args)
8
+ @full_args = full_args
9
+ end
10
+
11
+ def execute
12
+ parse_full_args
13
+ sanitize_members
14
+ return_message
15
+ end
16
+
17
+ private
18
+
19
+ def parse_full_args
20
+ index = (full_args.index('-t') || full_args.index('--t') || full_args.index('--team') || full_args.index('-team')) + 1
21
+ message_index = full_args.index('-m') || full_args.index('--message')
22
+
23
+ self.members_list = if !message_index || (message_index && (index > message_index))
24
+ full_args[index..-1]
25
+ else
26
+ full_args[index...message_index]
27
+ end
28
+ end
29
+
30
+ def sanitize_members
31
+ remove_trailing_commas!
32
+
33
+ if members_list.any? {|m| m.include?(',')}
34
+ split_members_list!
35
+ end
36
+
37
+ if !every_member_starts_with_at_symbol?
38
+ prepend_at_symbols!
39
+ end
40
+ end
41
+
42
+ def split_members_list!
43
+ members_list.map! do |m|
44
+ if m.include?(',')
45
+ m.split(',')
46
+ else
47
+ m
48
+ end
49
+ end
50
+
51
+ members_list.flatten!
52
+ end
53
+
54
+ def remove_trailing_commas!
55
+ members_list.map! {|m| m.chomp(',').strip}
56
+ end
57
+
58
+ def every_member_starts_with_at_symbol?
59
+ members_list.all? {|m| m.start_with?('@')}
60
+ end
61
+
62
+ def prepend_at_symbols!
63
+ members_list.each {|m| m.prepend('@') if !m.start_with?('@')}
64
+ end
65
+
66
+ def return_message
67
+ "team: #{self.members_list.join(' ')}"
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module Learn
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,257 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: learn-co-dev
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Flatiron School
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: learn-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.5.0.rc1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.5.0.rc1
69
+ - !ruby/object:Gem::Dependency
70
+ name: learn-config
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.77
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.77
83
+ - !ruby/object:Gem::Dependency
84
+ name: learn-open
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: learn-submit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: learn-doctor
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.3
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.3
125
+ - !ruby/object:Gem::Dependency
126
+ name: learn-generate
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.16
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 1.0.16
139
+ - !ruby/object:Gem::Dependency
140
+ name: learn-status
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 1.0.1
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 1.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: learn-hello
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 1.0.1
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: 1.0.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: learn_linter
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: 1.6.0
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: 1.6.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: netrc
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 0.11.0
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: 0.11.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: thor
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: 0.19.1
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: 0.19.1
209
+ description:
210
+ email:
211
+ - learn@flatironschool.com
212
+ executables:
213
+ - learn-dev
214
+ extensions: []
215
+ extra_rdoc_files: []
216
+ files:
217
+ - ".gitignore"
218
+ - Gemfile
219
+ - LICENSE.txt
220
+ - README.md
221
+ - Rakefile
222
+ - bin/learn-dev
223
+ - learn-co.gemspec
224
+ - lib/learn.rb
225
+ - lib/learn/cli.rb
226
+ - lib/learn/internet_connection.rb
227
+ - lib/learn/lab/parser.rb
228
+ - lib/learn/netrc_interactor.rb
229
+ - lib/learn/options_sanitizer.rb
230
+ - lib/learn/team_members/parser.rb
231
+ - lib/learn/version.rb
232
+ homepage: https://github.com/learn-co/learn-co
233
+ licenses:
234
+ - MIT
235
+ metadata: {}
236
+ post_install_message:
237
+ rdoc_options: []
238
+ require_paths:
239
+ - lib
240
+ - bin
241
+ required_ruby_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ requirements: []
252
+ rubyforge_project:
253
+ rubygems_version: 2.6.11
254
+ signing_key:
255
+ specification_version: 4
256
+ summary: The command line interface to Learn.co.
257
+ test_files: []