Sha256: 471532ed962061f6e35e4ca7c952b616c411993ce8d95563cb1169ec0e9cc9c7

Contents?: true

Size: 966 Bytes

Versions: 4

Compression:

Stored size: 966 Bytes

Contents

module Bebox
  class Cli
    include Bebox::Logger

    attr_accessor :project_root

    def initialize(*args)
      # add the GLI magic on to the Bebox::Cli instance
      self.extend GLI::App

      program_desc 'Create basic provisioning of remote servers.'
      version Bebox::VERSION

      if inside_project?
        self.extend Bebox::ProjectCommands
      else
        self.extend Bebox::GeneralCommands
      end
      exit run(*args)
    end

    # Search recursively for .bebox file to see
    # if current directory is a bebox project or not
    def inside_project?
      project_found = false
      cwd = Pathname(Dir.pwd)
      home_directory = File.expand_path('~')
      cwd.ascend do |current_path|
        project_found = File.file?("#{current_path.to_s}/.bebox")
        self.project_root = current_path.to_s if project_found
        break if project_found || (current_path.to_s == home_directory)
      end
      project_found
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bebox-0.1.3 lib/bebox/cli.rb
bebox-0.1.2 lib/bebox/cli.rb
bebox-0.1.1 lib/bebox/cli.rb
bebox-0.1.0 lib/bebox/cli.rb