14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/et/runner.rb', line 14
def go(args)
version VERSION
pre { |_, _, _, _| check_config! }
desc "Initialize current directory as a work area."
skips_pre
command :init do |c|
c.flag [:u, :user], desc: "Username"
c.flag [:t, :token], desc: "Login token"
c.flag [:h, :host], desc: "Server hosting the lessons"
c.action do |_global_options, options, _cmdargs|
settings = {
"username" => options[:user],
"token" => options[:token],
"host" => options[:host]
}
settings = prompt_for_missing(settings)
config.save!(settings)
puts "Saved configuration to #{config.path}"
end
end
desc "List available lessons."
command :list do |c|
c.action do |_global_options, _options, _cmdargs|
Formatter.print_table(api.list_lessons, 'slug', 'title', 'type')
end
end
desc "Download lesson to your working area."
command :get do |c|
c.action do |_global_options, _options, cmdargs|
cmdargs.each do |slug|
lesson = api.get_lesson(slug)
archive = api.download_file(lesson['archive_url'])
archive_manager = ET::ArchiveManager.new(archive, cwd)
archive_manager.unpack
if !archive_manager.unpacked_files.empty?
archive_manager.delete_archive
puts "'#{slug}' extracted to '#{archive_manager.destination}'"
else
raise StandardError.new("Failed to extract the archive.")
end
end
end
end
desc "Submit the lesson in this directory."
command :submit do |c|
c.action do |_global_options, _options, _cmdargs|
lesson = Lesson.new(cwd)
if lesson.exists?
api.submit_lesson(lesson)
puts "Lesson submitted"
else
raise StandardError.new("Not in a lesson directory.")
end
end
end
desc "Run an exercise test suite."
command :test do |c|
c.action do |_global_options, _options, _cmdargs|
exercise = Exercise.new(cwd)
if exercise.exists?
exercise.run_tests
else
raise StandardError.new("Not in an exercise directory.")
end
end
end
run(args)
end
|