<commit_before>require 'mamiya'

require 'mamiya/config'
require 'mamiya/script'
require 'mamiya/logger'

require 'mamiya/steps/build'
require 'mamiya/steps/push'
require 'mamiya/steps/fetch'
require 'mamiya/steps/extract'

require 'thor'

module Mamiya
  class CLI < Thor
    class_option :config, aliases: '-C', type: :string
    class_option :script, aliases: '-S', type: :string
    class_option :application, aliases: %w(-a --app), type: :string
    class_option :debug, aliases: %w(-d), type: :boolean
    class_option :color, type: :boolean
    class_option :no_color, type: :boolean
    # TODO: class_option :set, aliases: '-s', type: :array

    no_commands do
      def invoke_command(*)
        super
      rescue Exception => e
        logger.fatal "#{e.class}: #{e.message}"

        e.backtrace.map{ |_| _.prepend("\t") }.each do |line|
          logger.debug line
        end
      end
    end

    desc "status", "Show status of servers"
    def status
      # TODO:
    end

    desc "list-packages", "List packages in storage"
    method_option :name_only, aliases: '-n'
    def list_packages
      unless options[:name_only]
        puts "Available packages in #{application}:"
        puts ""
      end

      puts storage.packages.sort
    end

    desc "list-applications", "List applications in storage"
    def list_applications
      puts _applications.keys
    end

    desc "show PACKAGE", "Show package"
    def show(package)
      require 'pp'
      pp storage.meta(package)
    end

    # ---

    desc "deploy PACKAGE", "Run build->push->distribute->prepare->finalize"
    def deploy
    end
<commit_msg>mamiya show: support json, yaml output<commit_after>require 'mamiya'

require 'mamiya/config'
require 'mamiya/script'
require 'mamiya/logger'

require 'mamiya/steps/build'
require 'mamiya/steps/push'
require 'mamiya/steps/fetch'
require 'mamiya/steps/extract'

require 'thor'

module Mamiya
  class CLI < Thor
    class_option :config, aliases: '-C', type: :string
    class_option :script, aliases: '-S', type: :string
    class_option :application, aliases: %w(-a --app), type: :string
    class_option :debug, aliases: %w(-d), type: :boolean
    class_option :color, type: :boolean
    class_option :no_color, type: :boolean
    # TODO: class_option :set, aliases: '-s', type: :array

    no_commands do
      def invoke_command(*)
        super
      rescue Exception => e
        logger.fatal "#{e.class}: #{e.message}"

        e.backtrace.map{ |_| _.prepend("\t") }.each do |line|
          logger.debug line
        end
      end
    end

    desc "status", "Show status of servers"
    def status
      # TODO:
    end

    desc "list-packages", "List packages in storage"
    method_option :name_only, aliases: '-n'
    def list_packages
      unless options[:name_only]
        puts "Available packages in #{application}:"
        puts ""
      end

      puts storage.packages.sort
    end

    desc "list-applications", "List applications in storage"
    def list_applications
      puts _applications.keys
    end

    desc "show PACKAGE", "Show package"
    method_option :format, aliases: %w(-f), type: :string, default: 'pp'
    def show(package)
      meta = storage.meta(package)

      case options[:format]
      when 'pp'
        require 'pp'
        pp meta
      when 'json'
        require 'json'
        puts meta.to_json
      when 'yaml'
        require 'yaml'
        puts meta.to_yaml
      end
    end

    # ---

    desc "deploy PACKAGE", "Run build->push->distribute->prepare->finalize"
    def deploy
    end

{'fraction_non_alphanumeric': 0.11679240011176306, 'fraction_numerical': 0.0, 'mean_word_length': 2.638211382113821, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1500301', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1134, 'n_words': 330}