Sha256: 14905aa2e60568c7ca78c4dfb8c61ecbcd620988cab4239d736cde7f288e7dc5

Contents?: true

Size: 1016 Bytes

Versions: 1

Compression:

Stored size: 1016 Bytes

Contents

require 'thor'

module Slackpolice
  class CLI < Thor

    desc :archive, "archive no members channels"
    method_option :api_token, type: :string, required: true
    def archive
      archived_channels = client.archive
      archived_channels.each do |c|
        puts "archived: ##{c['name']}"
      end
    end

    desc :remove_files, "remove expired files"
    method_option :api_token, type: :string, required: true
    method_option :days, type: :numeric, default: 7
    method_option :dry_run, type: :boolean, default: false
    def remove_files
      dt = Date.today.prev_day(options['days'])
      if options[:dry_run]
        client.expired_files(dt).each do |f|
          puts "deleted: #{Time.at(f['created'])} #{f['title']} (dry-run)"
        end
      else
        client.delete_expired_files(dt).each do |f|
          puts "deleted: #{Time.at(f['created'])} #{f['title']}"
        end
      end
    end

    private

    def client
      @client ||= Slackpolice::Client.new options
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slackpolice-0.2.0 lib/slackpolice/cli.rb