class FakeFlorence::Cli

Public Class Methods

source_root() click to toggle source
# File lib/fake_florence/cli.rb, line 7
def self.source_root
  File.join(__dir__, '../../templates')
end

Public Instance Methods

announce() click to toggle source
# File lib/fake_florence/cli.rb, line 127
def announce
  abort "Florence is #{status_text}, please `#{set_colour 'flo start', :blue}` before announcing." unless daemon.running?
  Config.log.level = Logger::WARN
  res = cache.announce_all_now
  announcers = res[:announcers].map do |name|
    set_color name, :white
  end

  if announcers.any?
    puts "Announced #{set_color res[:features], :white} features to #{announcers.join(', ')}."
  else
    puts 'Did not announce any features.'
  end
end
clone(url) click to toggle source
# File lib/fake_florence/cli.rb, line 111
def clone(url)
  r = Retriever.new(url)

  r.each_feature do |feature|
    create_file(cache.id_to_file(feature.id)) do
      feature.saveable
    end
  end
rescue Retriever::HTTPFailure => e
  abort "HTTP error: #{e.message}"
rescue Retriever::NotFlorenceServerError
  abort "The given URL doesn't quack like a Florence server"
end
config() click to toggle source
# File lib/fake_florence/cli.rb, line 144
def config
  open_editor(Config.store_file)
end
create(id) click to toggle source
# File lib/fake_florence/cli.rb, line 98
def create(id)
  path = cache.id_to_file(id)
  copy_file('feature.yaml', path)
  open_editor(path)
  puts "#{set_color id, :white} created and opened for editing"
end
edit(id = nil) click to toggle source
# File lib/fake_florence/cli.rb, line 82
def edit(id = nil)
  path = id.nil? ? cache.root : cache.id_to_file(id)

  unless path.exist?
    puts "This feature doesn't exist. In future, `#{set_color "flo create #{id}", :blue}` will provide a template to start from."
  end

  open_editor(path)
  puts "#{set_color(id || 'The features folder', :white)} has been opened for editing"
end
help() click to toggle source
Calls superclass method
# File lib/fake_florence/cli.rb, line 11
    def help
      puts <<~MSG
      Fake Florence v#{VERSION} (#{status_text})

      This is a command line application which will help you with development of Florence & Determinator based experiments and feature flags.
      Find out more about specific commands with `#{set_color 'flo help [COMMAND]', :blue}`, but you're probably looking for:

        #{set_color '$ flo start', :blue}
        #{set_color '$ flo create my_experiment', :blue}

      MSG
      super
    end
logs() click to toggle source
# File lib/fake_florence/cli.rb, line 150
def logs
  exec("tail -f \"#{Config.logfile}\"")
end
start() click to toggle source
# File lib/fake_florence/cli.rb, line 38
    def start
      if daemon.running?
        abort 'Flo is already running.'
      else
        puts <<~MSG
        Flo is now #{set_color 'running', :green} at #{set_color Config.base_url, :white}
        Use other commands to create or edit Feature flags and Experiments.
        See `#{set_color 'flo help', :blue}` for more information
        MSG

        daemon.start(daemonize: options[:daemonize])
      end
    end
status() click to toggle source
# File lib/fake_florence/cli.rb, line 72
def status
  puts "Flo is #{status_text}"
end
stop() click to toggle source
# File lib/fake_florence/cli.rb, line 58
def stop
  if daemon.running?
    daemon.stop
    puts "Flo is now #{set_color 'stopped', :red}."
  else
    abort 'Flo was not running.'
  end
end

Private Instance Methods

cache() click to toggle source
# File lib/fake_florence/cli.rb, line 162
def cache
  @cache ||= FeatureCache.new(Config.home_dir)
end
daemon() click to toggle source
# File lib/fake_florence/cli.rb, line 166
def daemon
  @daemon ||= FakeFlorence::Daemon.new
end
open_editor(path) click to toggle source
# File lib/fake_florence/cli.rb, line 156
def open_editor(path)
  abort "Unsure how to edit #{path.to_s}\nEDITOR variable is empty" unless ENV['EDITOR']
  system("$EDITOR \"#{path.to_s}\"")
  abort "Flo failed to open #{path.to_s} for editing" unless $CHILD_STATUS.exitstatus == 0
end
status_text() click to toggle source
# File lib/fake_florence/cli.rb, line 170
def status_text
  daemon.running? ? set_color('running', :green) : set_color('stopped', :red)
end