Class: FakeFlorence::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/fake_florence/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



7
8
9
# File 'lib/fake_florence/cli.rb', line 7

def self.source_root
  File.join(__dir__, '../../templates')
end

Instance Method Details

#announceObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# 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) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
# 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

#configObject



144
145
146
# File 'lib/fake_florence/cli.rb', line 144

def config
  open_editor(Config.store_file)
end

#create(id) ⇒ Object



98
99
100
101
102
103
# 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) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# 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

#helpObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fake_florence/cli.rb', line 11

def help
  puts "  Fake Florence v\#{VERSION} (\#{status_text})\n\n  This is a command line application which will help you with development of Florence & Determinator based experiments and feature flags.\n  Find out more about specific commands with `\#{set_color 'flo help [COMMAND]', :blue}`, but you're probably looking for:\n\n    \#{set_color '$ flo start', :blue}\n    \#{set_color '$ flo create my_experiment', :blue}\n\n  MSG\n  super\nend\n"

#logsObject



150
151
152
# File 'lib/fake_florence/cli.rb', line 150

def logs
  exec("tail -f \"#{Config.logfile}\"")
end

#startObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fake_florence/cli.rb', line 38

def start
  if daemon.running?
    abort 'Flo is already running.'
  else
    puts "    Flo is now \#{set_color 'running', :green} at \#{set_color Config.base_url, :white}\n    Use other commands to create or edit Feature flags and Experiments.\n    See `\#{set_color 'flo help', :blue}` for more information\n    MSG\n\n    daemon.start(daemonize: options[:daemonize])\n  end\nend\n"

#statusObject



72
73
74
# File 'lib/fake_florence/cli.rb', line 72

def status
  puts "Flo is #{status_text}"
end

#stopObject



58
59
60
61
62
63
64
65
# 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