Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check parent directories for Cakefiles #1687

Merged
merged 2 commits into from
Sep 12, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/cake.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ helpers.extend global,
# asynchrony may cause tasks to execute in a different order than you'd expect.
# If no tasks are passed, print the help screen.
exports.run = ->
path.exists 'Cakefile', (exists) ->
throw new Error("Cakefile not found in #{process.cwd()}") unless exists
args = process.argv.slice 2
CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
oparse = new optparse.OptionParser switches
return printTasks() unless args.length
options = oparse.parse(args)
invoke arg for arg in options.arguments
process.chdir findCakefilePathSync(fs.realpathSync '.')
args = process.argv.slice 2
CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
oparse = new optparse.OptionParser switches
return printTasks() unless args.length
options = oparse.parse(args)
invoke arg for arg in options.arguments

# Display the list of Cake tasks in a format similar to `rake -T`
printTasks = ->
Expand All @@ -67,3 +66,11 @@ printTasks = ->
missingTask = (task) ->
console.log "No such task: \"#{task}\""
process.exit 1

# Search in current and parent directories for Cakefile
findCakefilePathSync = (curPath) ->
return curPath if path.existsSync path.join(curPath, 'Cakefile')
parent = path.normalize path.join(curPath, '..')
return findCakefilePathSync parent unless parent == curPath
# None found
throw new Error("Cakefile not found in #{process.cwd()}")