<commit_before>require 'terminal-table'
require 'mustache'

command :query do |c|
  c.syntax = 'jm query [options] query'
  c.summary = 'Get the keys from a jira query'
  c.description = 'Run a JQL query. '
  c.example 'Get Open issues and dump everything', %{jm query status=Open --all_fields --json}
  c.example 'Get All Open issues and dump everything', %{jm query --raw status=Open --all_fields --json}
  c.example 'Show info about an issue', %{jm query --style info BUG-24}
  c.example 'Show info about an issue', %{jm info BUG-24}

  c.option '--style STYLE', String, 'Which output style to use'

  c.option '--[no-]raw', 'Do not prefix query with project and assignee'
  c.option '--[no-]json', 'Output json reply instead of styled output'

  c.option '--fields FIELDS', Array, 'Which fields to return.'
  c.option '--all_fields', 'Return all fields'

  c.action do |args, options|
    options.default(
      :json => false,
      :all_fields => false,
      :style => 'basic',
      :raw=> true
    )

    allOfThem = {
      :basic => {
        :fields => [:key, :summary],
        :format_type => :strings,
        :format => %{{{key}} {{summary}}},
      },
      :info => {
        :fields => [:key, :summary, :description, :assignee, :reporter, :priority,
                    :issuetype, :status, :resolution, :votes, :watches],
        :format_type => :strings,
        :format => %{{{key}}
    Summary: {{summary}}
   Reporter: {{reporter.displayName}}
   Assignee: {{assignee.displayName}}
       Type: {{issuetype.name}} ({{priority.name}})
     Status: {{status.name}} (Resolution: {{resolution.name}})
    Watches: {{watches.watchCount}}  Votes: {{votes.votes}}
Description: {{description}}
        }
      },
      :test_table => {
        :fields => [:key, :assignee],
        :format_type => :table_columns,
        :header => [],
        :format => [%{{{key}}}, %{{{assignee.displayName}}}]
      },
      :prgs => {
        :fields => [:key, :workratio, :aggregatetimespent, :duedate,
                    :aggregatetimeoriginalestimate],
        :format_type => :table_rows, # :table_columns
        :header => [:key, :workratio, :aggregatetimespent, :duedate,
                    :aggregatetimeoriginalestimate],
        :format => [%{{{key}}}, %{{{workratio}}},
                    %{{{aggregatetimespent}}},
                    %{{{duedate}}},
                    %{{{aggregatetimeoriginalestimate}}},
        ]
      },
    }

    theStyle = allOfThem[options.style.to_sym]
    if theStyle.nil? then
      say_error "No style \"#{options.style}\""
      exit 2
    end
    #### look for command line overrides
    theStyle[:fields] = options.fields if options.fields
<commit_msg>Some initial ideas for defined method columns<commit_after>require 'terminal-table'
require 'mustache'

command :query do |c|
  c.syntax = 'jm query [options] query'
  c.summary = 'Get the keys from a jira query'
  c.description = 'Run a JQL query. '
  c.example 'Get Open issues and dump everything', %{jm query status=Open --all_fields --json}
  c.example 'Get All Open issues and dump everything', %{jm query --raw status=Open --all_fields --json}
  c.example 'Show info about an issue', %{jm query --style info BUG-24}
  c.example 'Show info about an issue', %{jm info BUG-24}

  c.option '--style STYLE', String, 'Which output style to use'

  c.option '--[no-]raw', 'Do not prefix query with project and assignee'
  c.option '--[no-]json', 'Output json reply instead of styled output'

  c.option '--fields FIELDS', Array, 'Which fields to return.'
  c.option '--all_fields', 'Return all fields'

  c.action do |args, options|
    options.default(
      :json => false,
      :all_fields => false,
      :style => 'basic',
      :raw=> true
    )

    allOfThem = {
      :basic => {
        :fields => [:key, :summary],
        :format_type => :strings,
        :format => %{{{key}} {{summary}}},
      },
      :info => {
        :fields => [:key, :summary, :description, :assignee, :reporter, :priority,
                    :issuetype, :status, :resolution, :votes, :watches],
        :format_type => :strings,
        :format => %{{{key}}
    Summary: {{summary}}
   Reporter: {{reporter.displayName}}
   Assignee: {{assignee.displayName}}
       Type: {{issuetype.name}} ({{priority.name}})
     Status: {{status.name}} (Resolution: {{resolution.name}})
    Watches: {{watches.watchCount}}  Votes: {{votes.votes}}
Description: {{description}}
        }
      },
      :test_table => {
        :fields => [:key, :assignee],
        :format_type => :table_columns,
        :header => [],
        :format => [%{{{key}}}, %{{{assignee.displayName}}}]
      },
      :prgs => {
        :fields => [:key, :workratio, :aggregatetimespent, :duedate,
                    :aggregatetimeoriginalestimate],
        :format_type => :table_rows, # :table_columns
        :header => [:key, :workratio, :aggregatetimespent, :duedate,
                    :aggregatetimeoriginalestimate],
        :format => [%{{{key}}}, %{{{workratio}}},
                    %{{{aggregatetimespent}}},
                    %{{{duedate}}},
                    %{{{aggregatetimeoriginalestimate}}},
        ],
        # I'm not sure.
        :methods => {
          :estimate => lambda do |issue|
            "%.2f"%[(issue[:aggregatetimeoriginalestimate] or 0) / 3600.0]
          end,
          :progress => lambda do |issue|
            "%.2f"%[(issue[:aggregatetimespent] or 0) / 3600.0]
          end,
          :percent => lambda do |issue|
            percent = issue[:workratio]
            if percent < 0 then
              estimate = (issue[:aggregatetimeoriginalestimate] or 0) / 3600.0
              if estimate > 0 then
                progress = (issue[:aggregatetimespent] or 0) / 3600.0
                percent = (progress / estimate * 100).floor
              else
                percent = 100
              end
            end
            "%.1f"%[percent]
          end
        }
      },
    }

    theStyle = allOfThem[options.style.to_sym]
    if theStyle.nil? then
      say_error "No style \"#{options.style}\""
      exit 2
    end
    #### look for command line overrides
    theStyle[:fields] = options.fields if options.fields

{'fraction_non_alphanumeric': 0.159397049390635, 'fraction_numerical': 0.007216164207825529, 'mean_word_length': 2.331730769230769, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 52, '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': '2110661', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1888, 'n_words': 513}