diff --git a/src/cb/token.cr b/src/cb/token.cr index c37b9f9..dc83fdc 100644 --- a/src/cb/token.cr +++ b/src/cb/token.cr @@ -1,5 +1,31 @@ require "./cacheable" +# TODO (abrightwell): We had to explicitly qualify this class name as an +# `Action` due to conflicts with the below `Token` struct. Would be great to +# potentially namespace actions under `CB::Action` or something. Something +# perhaps worth considering. +class CB::TokenAction < CB::Action + enum Format + Default + Header + end + + property token : Token + property format : Format = Format::Default + + def initialize(@token, @input, @output) + end + + def run + case @format + when "header" + output << "Authorization: Bearer #{token.token}" + when "default" + output << token.token + end + end +end + struct CB::Token Cacheable.include key: host getter host : String diff --git a/src/cli.cr b/src/cli.cr index b7d38bb..a675040 100755 --- a/src/cli.cr +++ b/src/cli.cr @@ -440,10 +440,9 @@ op = OptionParser.new do |parser| parser.on("token", "Return a bearer token for use in the api") do parser.banner = "cb token [-H]" - action = ->{ puts PROG.token.token } - parser.on("-H", "Authorization header format") do - action = ->{ puts "Authorization: Bearer #{PROG.token.token}" } - end + token = action = CB::TokenAction.new PROG.token, PROG.input, PROG.output + + parser.on("-H", "Authorization header format") { token.format = CB::TokenAction::Format::Header } end parser.on("version", "Show the version") do