require 'thor'
require 'colorize'
require 'power-build/constructor'
require 'power-build/github_manager'

module PowerBuild
  class Base < Thor
    desc "build, b", "Generates a static site. Existing files will be overwritten."
    map %w[b] => :build
    default_task :build
    def build 
      if File.file? "power-build.config"
        Constructor.new.copy_assets
        Constructor.new(:config).generate_site
        puts "Done!"
      else
        puts "No config file found. Run 'power init' first."
      end
    end

    desc "init, i", "Start with a config file."
    map %w[i] => :init
    def init
      unless in_power_build_project
        Constructor.new.build_config
      else
        puts "Already in a power-build project."
      end
    end

    desc "delete, d", "Remove all files generated by Power Build"
    map %w[d] => :delete
    def delete
      Constructor.new.remove_config
    end

    desc "config, open, o", "Open the config file for you if you're this lazy"
    map %w[open, o] => :config
    def config
      Constructor.new.open_config
    end

    map %w[--version -v] => :__print_version
    desc "--version, -v", "show version"
    def __print_version
      puts PowerBuild::VERSION
    end

    # desc "push, p", "Push to GitHub"
    # map %w[push, p] => :push
    # def push
    #   GitHubManager.new.checkout_branch
    # end

    private
      def in_power_build_project
        count = Dir.pwd.count("/") - 1
        for i in 0..count do
         @respond = true if File.file?("../" * i + "power-build.config")
        end
        return @respond
      end
  end
end
