-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.rb
More file actions
150 lines (121 loc) · 4.21 KB
/
cli.rb
File metadata and controls
150 lines (121 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require "optparse"
require "json"
require_relative "commands"
module FeaturevisorCLI
class Options
attr_accessor :command, :assertion_pattern, :context, :environment, :feature,
:key_pattern, :n, :only_failures, :quiet, :variable, :variation,
:verbose, :inflate, :show_datafile, :schema_version, :project_directory_path,
:populate_uuid, :with_scopes, :with_tags
def initialize
@n = 1000
@project_directory_path = Dir.pwd
@populate_uuid = []
end
end
class Parser
def self.parse(args)
options = Options.new
if args.empty?
return options
end
options.command = args[0]
remaining_args = args[1..-1]
OptionParser.new do |opts|
opts.banner = "Usage: featurevisor [command] [options]"
opts.on("--assertionPattern=PATTERN", "Assertion pattern") do |v|
options.assertion_pattern = v
end
opts.on("--context=CONTEXT", "Context JSON") do |v|
options.context = v
end
opts.on("--environment=ENV", "Environment (required for benchmark)") do |v|
options.environment = v
end
opts.on("--feature=FEATURE", "Feature key (required for benchmark)") do |v|
options.feature = v
end
opts.on("--keyPattern=PATTERN", "Key pattern") do |v|
options.key_pattern = v
end
opts.on("-n", "--iterations=N", "--n=N", Integer, "Number of iterations (default: 1000)") do |v|
options.n = v
end
opts.on("--onlyFailures", "Only show failures") do
options.only_failures = true
end
opts.on("--quiet", "Quiet mode") do
options.quiet = true
end
opts.on("--variable=VARIABLE", "Variable key") do |v|
options.variable = v
end
opts.on("--variation", "Variation mode") do
options.variation = true
end
opts.on("--verbose", "Verbose mode") do
options.verbose = true
end
opts.on("--inflate=N", Integer, "Inflate mode") do |v|
options.inflate = v
end
opts.on("--showDatafile", "Show datafile content for each test") do
options.show_datafile = true
end
opts.on("--schemaVersion=VERSION", "Schema version") do |v|
options.schema_version = v
end
opts.on("--with-scopes", "--withScopes", "Test scoped assertions against scoped datafiles") do
options.with_scopes = true
end
opts.on("--with-tags", "--withTags", "Test tagged assertions against tagged datafiles") do
options.with_tags = true
end
opts.on("--projectDirectoryPath=PATH", "Project directory path") do |v|
options.project_directory_path = v
end
opts.on("--populateUuid=KEY", "Populate UUID for attribute key") do |v|
options.populate_uuid << v
end
opts.on("-h", "--help", "Show this help message") do
puts opts
exit
end
end.parse!(remaining_args)
options
end
end
def self.run(args)
options = Parser.parse(args)
case options.command
when "test"
Commands::Test.run(options)
when "benchmark"
Commands::Benchmark.run(options)
when "assess-distribution"
Commands::AssessDistribution.run(options)
else
show_help
end
end
def self.show_help
puts "Featurevisor Ruby SDK CLI"
puts ""
puts "Usage: featurevisor [command] [options]"
puts ""
puts "Commands:"
puts " test Run tests for features and segments"
puts " benchmark Benchmark feature evaluation performance"
puts " assess-distribution Assess feature distribution across contexts"
puts ""
puts "Learn more at https://featurevisor.com/docs/sdks/ruby/"
puts ""
puts "Examples:"
puts " featurevisor test"
puts " featurevisor test --keyPattern=pattern"
puts " featurevisor benchmark --feature=myFeature --environment=dev --n=10000"
puts " featurevisor assess-distribution --feature=myFeature --n=10000"
puts ""
puts "Note: benchmark command requires --environment and --feature options"
end
end