Skip to content

Commit

Permalink
Fixing the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Yacine Petitprez committed Mar 21, 2018
1 parent 79ebc5d commit d9161d4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/clear/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ module Clear::CLI
when "--verbose"
Clear.logger.level = ::Logger::DEBUG
next
when "db"
Clear::CLI::DB.run(args)
when "migration"
ensure_in_custom_project
Clear::CLI::Migration.run(args)
Expand Down
28 changes: 28 additions & 0 deletions src/clear/cli/db.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# The `db` command
#
# # Commands
#
module Clear::CLI::DB
def self.display_help_and_exit(opts)
puts <<-HELP
clear-cli [cli-options] db [db-command]
Commands:
create # Create the database
HELP

exit
end

def self.run(args)
OptionParser.parse(args) do |opts|
opts.unknown_args do |args, options|
arg = args.shift
case arg
when "create"
exit
end
end
end
end
end
4 changes: 2 additions & 2 deletions templates/kemal/config/database.yml.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ production:
uri: link_to_production_db

development:
uri: postgres://postgres@localhost/$(app_name_underscore)_development
uri: postgres://postgres@localhost/<%= opts[:app_name_underscore] %>_development

test:
uri: postgres://postgres@localhost/$(app_name_underscore)_test
uri: postgres://postgres@localhost/<%= opts[:app_name_underscore] %>_test
2 changes: 1 addition & 1 deletion templates/kemal/src/controllers/application_controller.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ApplicationController
scope = "/#{scope}"
end

if scope[-1] == "/"
if scope[-1] == '/'
scope = scope + path
else
scope = scope + "/" + path
Expand Down
18 changes: 9 additions & 9 deletions templates/kemal/src/db/init.ecr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require "yaml"
# Initialize Clear with the database.yml file
CLEAR_CONFIG = YAML.parse(File.read("./config/database.yml"))[Application.env]
CLEAR_DB_CONFIG = YAML.parse(File.read("./config/database.yml"))[Application.env]

uri = CLEAR_CONFIG["uri"].as_s
def self.init_db
uri = CLEAR_DB_CONFIG["uri"].as_s

begin
Clear::SQL.init(CLEAR_CONFIG["uri"].as_s)
rescue DB::ConnectionRefused
puts "FATAL: Connection to the database (#{uri}) has been refused"
exit
end
begin
Clear::SQL.init(CLEAR_DB_CONFIG["uri"].as_s)
rescue DB::ConnectionRefused
puts "FATAL: Connection to the database (#{uri}) has been refused"
end
end
2 changes: 1 addition & 1 deletion templates/kemal/src/views/components/footer.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module TreeTemplate::Components
footer do
p(style: "text-align: center") do
# test
unsafe "&copy; $app_name - #{content}"
unsafe "&copy; <%= opts[:app_name] %> - #{content}"
end
end
end
Expand Down
1 change: 0 additions & 1 deletion templates/kemal/src/views/layouts/application.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module View::Layouts
t.div id: "app" do
t.yield
end
t.app_footer("meh?")
end
end
end
Expand Down

0 comments on commit d9161d4

Please sign in to comment.