#!/usr/bin/env ruby require "tty-prompt" require "zup/generator" require "zup/swagger" @zup = Zup::Generator.new @swagger = Zup::Swagger.new @prompt = TTY::Prompt.new @header = """ ######################################################################## ######################################################################## ###### ###### ###### Zup Generator v1 ###### ###### ###### ###### Generate code for connect gateway rest. ###### ###### ###### ######################################################################## ######################################################################## """ def login(error = false) system("clear") puts @header puts "Login e senha inválidos.\n\n" if error heart = @prompt.decorate('🍺 ') user = @prompt.ask('Qual o seu e-mail da zup?', default: ENV['USER']) pass = @prompt.mask("Qual sua senha?", mask: heart) if @zup.login(user, pass) puts "LOGADO" else login(true) end end def load_data system("clear") puts @header puts "Carregando todas as informações necessárias...\n" puts "Isso pode levar alguns minutos...\n\n" @zup.load_data end def choice_api system("clear") puts @header apis = @zup.list_apis selected = @prompt.select("Qual API você quer conectar?", apis.map { |e| e[:name] }) @api = apis.select {|e| e[:name] == selected}.first choice_version end def choice_version versions = @zup.list_versions(@api[:id]) selected = @prompt.select("Qual versão da API?", versions.map { |e| e[:path] }) @version = versions.select {|e| e[:path] == selected}.first choice_action end def choice_action system("clear") puts @header puts """ API SELECIONADA: #{@api[:name]} VERSAO SELECIONADA: #{@version[:path]} """ selected = @prompt.select("Qual ação deseja fazer?", [ "Copiar para Clipboard o YAML", "Gerar pacote de Client", "Selecionar outra API", "Sair", ]) case selected when "Copiar para Clipboard o YAML" copy_yaml when "Selecionar outra API" choice_api when "Gerar pacote de Client" export_client when "Sair" sair end end def copy_yaml @zup.pbcopy @zup.generate_swagger(@api[:id], @version[:id], "yaml") choice_action end def export_client system("clear") puts @header if @swagger.installed? select_language generate_files else tutorial_install_swagger end end def select_language system("clear") puts @header @lang = @prompt.select("Qual a linguágem do client que deseja gerar?", @swagger.languages) end def generate_files system("clear") puts @header select_output puts "Gerando..." content = @zup.generate_swagger(@api[:id], @version[:id]) @swagger.generate(content, @lang, @output) choice_action end def select_output system("clear") puts @header @output = @prompt.ask('Onde deseja salvar?', default: "output/") end def tutorial_install_swagger puts """ O swagger-codegen não está instalado em sua maquina. """ end def sair system("clear") end login load_data choice_api