Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Includes totally revamped, easy to use command line interface.
- Loading branch information
Pedro Maciel
committed
Oct 16, 2018
1 parent
e082bfa
commit dd094c9
Showing
67 changed files
with
818 additions
and
508 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.5.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
# | ||
# This file was generated by Bundler. | ||
# | ||
# The application 'old-coltrane' is installed as part of a gem, and | ||
# this file is here to facilitate running it. | ||
# | ||
|
||
require "pathname" | ||
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", | ||
Pathname.new(__FILE__).realpath) | ||
|
||
bundle_binstub = File.expand_path("../bundle", __FILE__) | ||
|
||
if File.file?(bundle_binstub) | ||
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ | ||
load(bundle_binstub) | ||
else | ||
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. | ||
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") | ||
end | ||
end | ||
|
||
require "rubygems" | ||
require "bundler/setup" | ||
|
||
load Gem.bin_path("coltrane", "old-coltrane") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,101 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) | ||
|
||
require 'paint' | ||
require 'color' | ||
|
||
require 'pedrozath-mercenary' | ||
require 'coltrane/commands' | ||
$debug = require 'pry' | ||
require 'coltrane/ui' | ||
|
||
if ENV['COLORTERM'] == 'truecolor' | ||
Paint.mode = 0xFFFFFF | ||
else | ||
Paint.mode = 0 | ||
puts "This terminal doesn't seem to support true color. " \ | ||
"Try something like iTerm2 (for macOS), VTE or Konsole (for linux) or Hyper" \ | ||
" (for Windows) and you'll see the true magic!" | ||
def debugger | ||
binding.pry unless $debug | ||
end | ||
|
||
Mercenary.program(:Coltrane) do |p| | ||
p.version Coltrane::VERSION | ||
p.description <<~DESC | ||
A music querying interface | ||
by Pedro Maciel (pedro@pedromaciel.com) | ||
module Coltrane | ||
module Cli | ||
class App | ||
attr_reader :router | ||
|
||
Check the chat room for project help/discussion/contribution: https://coltrane-ruby.herokuapp.com | ||
DESC | ||
p.syntax 'coltrane <subcommand> [options]' | ||
def self.start(initial_route) | ||
if ENV['COLORTERM'] == 'truecolor' | ||
Paint.mode = 0xFFFFFF | ||
else | ||
Paint.mode = 0 | ||
puts "This terminal doesn't seem to support true color. " \ | ||
"Try something like iTerm2 (for macOS), VTE or Konsole (for linux) or Hyper" \ | ||
" (for Windows) and you'll see the true magic!" | ||
end | ||
|
||
Coltrane::Commands::Command.subclasses.each do |command| | ||
command.mercenary_init(p) | ||
end | ||
path, params = initial_route.split(' ').each_with_object([nil, {}]) do |segment, memo| | ||
if segment =~ /:/ | ||
key, value = segment.split(':') | ||
memo[1].merge!([[key.to_sym, value.gsub('-', ' ')]].to_h) | ||
else | ||
memo[0] = [memo[0], segment].compact.join(' ') | ||
end | ||
end | ||
|
||
p.command(:about) do |c| | ||
c.description 'Shows this screen' | ||
c.action { puts p } | ||
end | ||
response = {path: (path || ''), **params} | ||
loop { response = app.flow(**response) } | ||
end | ||
|
||
p.command(:shell) do |c| | ||
c.description 'Starts an interactive shell' | ||
c.action do | ||
system File.expand_path('../../bin', __FILE__) + "/coltrane-interactive" | ||
end | ||
end | ||
def self.app | ||
@app ||= new | ||
end | ||
|
||
def initialize | ||
@router = Router.new | ||
end | ||
|
||
p.command(:help) do |c| | ||
c.description 'May give you some help.' | ||
c.syntax 'help <command> [subcommand, sub-subcommand, ...]' | ||
c.action do |(*command_path), _options| | ||
if command_path.empty? | ||
puts p | ||
else | ||
puts begin | ||
command_path.reduce(p) do |memo, key| | ||
memo.commands.delete(key.to_sym) | ||
end || "\n Sorry, command found." | ||
def ask_questions(questions) | ||
questions.map { |name, question| [name, ask_question(question)] }.to_h | ||
end | ||
|
||
def ask_question(question) | ||
CLI::UI::Prompt.ask(question[:statement], options: question[:options]) | ||
end | ||
|
||
def navigation(params) | ||
return {} if params.empty? | ||
CLI::UI::Prompt.ask('What to do now?') do |h| | ||
params.each do |key, _value| | ||
h.option("Different #{key}") { params[key] = nil } | ||
end | ||
h.option("Go back") { params[:path] = '' } | ||
end | ||
params | ||
end | ||
|
||
def output(response) | ||
return unless response[:content] | ||
puts [ | ||
nil, | ||
"-> coltrane #{router.url}", | ||
nil, | ||
response[:content], | ||
nil | ||
] | ||
end | ||
|
||
def flow(response) | ||
raise 'Response is empty' unless response | ||
output(response) | ||
response.delete(:content) | ||
questions = response&.delete(:questions) || {} | ||
response.merge!(navigation(response)) unless response.has_key?(:path) || questions.any? | ||
response.merge!(ask_questions(questions)) if questions.any? | ||
exit if response[:path] == 'exit' | ||
router.get(**response.compact) | ||
rescue => e | ||
response.delete(:path) | ||
puts e | ||
puts e.backtrace if $debug | ||
retry | ||
end | ||
|
||
def exit | ||
Kernel.exit(0) | ||
end | ||
end | ||
end | ||
|
||
p.default_command(:shell) | ||
end | ||
|
||
Coltrane::Cli::App.start(ARGV.join(' ')) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Coltrane | ||
module Commands | ||
class AvailableChordRepresentations < Command | ||
def run | ||
return ['GuitarChordChart'] + AvailableRepresentations.run | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Coltrane | ||
module Commands | ||
class AvailableClassicScales < Command | ||
def run | ||
Theory::Scale.known_scales | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Coltrane | ||
module Commands | ||
class AvailableNotableProgressions < Command | ||
def run | ||
Theory::NotableProgressions::PROGRESSIONS.keys | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Coltrane | ||
module Commands | ||
class AvailableRepresentations < Command | ||
def run | ||
['Text'] + Representation.constants.map(&:to_s) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.