From 09dac218c443eabc3cabc06a15412585509d0b46 Mon Sep 17 00:00:00 2001 From: taicsuzu Date: Sun, 13 Nov 2016 12:21:19 +0900 Subject: [PATCH] added feature --- spec/compiler/compiler_spec.cr | 7 +++++++ spec/compiler/data/shard.yml | 1 + spec/compiler/data/src/dummy-proj.cr | 0 src/compiler/crystal/command.cr | 24 ++++++++++++++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 spec/compiler/data/shard.yml create mode 100644 spec/compiler/data/src/dummy-proj.cr diff --git a/spec/compiler/compiler_spec.cr b/spec/compiler/compiler_spec.cr index c06cb59e9f63..7a2c523ff86f 100644 --- a/spec/compiler/compiler_spec.cr +++ b/spec/compiler/compiler_spec.cr @@ -25,4 +25,11 @@ describe "Compiler" do `#{tempfile.path}`.should eq("Hello!") end end + + it "build a project without specified sources" do + Dir.cd "#{__DIR__}/data/" do + Crystal::Command.run ["build"] + File.delete("dummy-proj") + end + end end diff --git a/spec/compiler/data/shard.yml b/spec/compiler/data/shard.yml new file mode 100644 index 000000000000..388f17a3ddeb --- /dev/null +++ b/spec/compiler/data/shard.yml @@ -0,0 +1 @@ +name: dummy-proj diff --git a/spec/compiler/data/src/dummy-proj.cr b/spec/compiler/data/src/dummy-proj.cr new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/src/compiler/crystal/command.cr b/src/compiler/crystal/command.cr index 2ea181d5982b..d36367252346 100644 --- a/src/compiler/crystal/command.cr +++ b/src/compiler/crystal/command.cr @@ -9,6 +9,7 @@ # an executable. require "json" +require "yaml" require "./command/*" class Crystal::Command @@ -388,8 +389,17 @@ class Crystal::Command end if filenames.size == 0 || (cursor_command && cursor_location.nil?) - puts option_parser - exit 1 + unless shard_yml_exists? + puts option_parser + exit 1 + else + if shard_proj_name.is_a?(String) + filenames << "./src/#{shard_proj_name}.cr" + else + error "\'name\' key is missing in shard.yml" + exit 1 + end + end end sources = gather_sources(filenames) @@ -457,6 +467,16 @@ class Crystal::Command values end + private def shard_yml_exists? + return true if File.exists?("shard.yml") && File.file?("shard.yml") + false + end + + private def shard_proj_name + config = YAML.parse(File.read("shard.yml")).as_h + config["name"].to_s if config.has_key?("name") + end + private def error(msg, exit_code = 1) # This is for the case where the main command is wrong @color = false if ARGV.includes?("--no-color")