<commit_before>module Kontena::Cli::Cloud::Master
  class AddCommand < Kontena::Command

    include Kontena::Cli::Common

    callback_matcher 'cloud-master', 'create'

    requires_current_account_token

    parameter "[NAME]", "Master name"

    option ['--redirect-uri'], '[URL]',      'Set master redirect URL'
    option ['--url'],          '[URL]',      'Set master URL'
    option ['--provider'],     '[NAME]',     'Set master provider'
    option ['--name'],         '[NAME]',     'Set master name',        hidden: true
    option ['--version'],      '[VERSION]',  'Set master version',     hidden: true
    option ['--owner'],        '[NAME]',     'Set master owner',       hidden: true

    option ['--id'],      :flag, 'Just output the ID'
    option ['--return'],  :flag, 'Return the ID', hidden: true
    option ['--force'],   :flag, "Don't ask questions"

    option ['--cloud-master-id'], '[ID]', "Use existing cloud master ID", hidden: true
    option ['--current'], :flag, 'Register and configure current master', hidden: true

    def register(name, url = nil, provider = nil, redirect_uri = nil, version = nil, owner = nil)
      attributes = {}
      attributes['name']         = name
      attributes['url']          = url if url
      attributes['provider']     = provider if provider
      attributes['redirect-uri'] = redirect_uri if redirect_uri
      attributes['version']      = version if version
      attributes['owner']        = owner if owner

      response = cloud_client.post('user/masters', { data: { attributes: attributes } })
      exit_with_error "Failed (invalid response)" unless response.kind_of?(Hash)
      exit_with_error "Failed: #{response['error']}" if response['error']
      exit_with_error "Failed (no data)" unless response['data']
      response
    end

    def get_existing(id)
      cloud_client.get("user/masters/#{id}")
    end

    def cloud_masters
      masters = []
      spinner "Retrieving a list of your registered Kontena Masters in Kontena Cloud" do |spin|
        begin
          masters = Kontena.run!(%w(cloud master list --return))
        rescue SystemExit
          spin.fail
        end
      end<commit_msg>Fix unnecessary spinner nesting during master deploy wizard (#2660)<commit_after>module Kontena::Cli::Cloud::Master
  class AddCommand < Kontena::Command

    include Kontena::Cli::Common

    callback_matcher 'cloud-master', 'create'

    requires_current_account_token

    parameter "[NAME]", "Master name"

    option ['--redirect-uri'], '[URL]',      'Set master redirect URL'
    option ['--url'],          '[URL]',      'Set master URL'
    option ['--provider'],     '[NAME]',     'Set master provider'
    option ['--name'],         '[NAME]',     'Set master name',        hidden: true
    option ['--version'],      '[VERSION]',  'Set master version',     hidden: true
    option ['--owner'],        '[NAME]',     'Set master owner',       hidden: true

    option ['--id'],      :flag, 'Just output the ID'
    option ['--return'],  :flag, 'Return the ID', hidden: true
    option ['--force'],   :flag, "Don't ask questions"

    option ['--cloud-master-id'], '[ID]', "Use existing cloud master ID", hidden: true
    option ['--current'], :flag, 'Register and configure current master', hidden: true

    def register(name, url = nil, provider = nil, redirect_uri = nil, version = nil, owner = nil)
      attributes = {}
      attributes['name']         = name
      attributes['url']          = url if url
      attributes['provider']     = provider if provider
      attributes['redirect-uri'] = redirect_uri if redirect_uri
      attributes['version']      = version if version
      attributes['owner']        = owner if owner

      response = cloud_client.post('user/masters', { data: { attributes: attributes } })
      exit_with_error "Failed (invalid response)" unless response.kind_of?(Hash)
      exit_with_error "Failed: #{response['error']}" if response['error']
      exit_with_error "Failed (no data)" unless response['data']
      response
    end

    def get_existing(id)
      cloud_client.get("user/masters/#{id}")
    end

    def cloud_masters
      masters = []
      spinner "Retrieving a list of your registered Kontena Masters in Kontena Cloud" do |spin|
        begin
          masters = Kontena.run!(%w(cloud master list --return --quiet))
        rescue SystemExit
          spin.fail
        end
      end
{'fraction_non_alphanumeric': 0.13972911963882617, 'fraction_numerical': 0.0009029345372460496, 'mean_word_length': 2.6863560732113143, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4256039', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1215, 'n_words': 388}