<commit_before>require 'thor'

module LicenseFinder
  class CLI < Thor
    option :quiet, type: :boolean, aliases: :q
    desc "rescan", "Find new dependencies."
    def rescan
      spinner {
        BundleSyncer.sync!
        Reporter.write_reports
      }

      action_items
    end
    default_task :rescan

    desc "approve DEPENDENCY_NAME", "Approve a dependency by name."
    def approve(name)
      dependency = Dependency.first(name: name)
      dependency.approve!

      say "The #{dependency.name} dependency has been approved!", :green

      Reporter.write_reports
    end

    desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license."
    def license(license, name)
      dependency = Dependency.first(name: name)
      dependency.set_license_manually license

      say "The #{name} dependency has been marked as using #{license} license!", :green

      Reporter.write_reports
    end

    desc "move", "Move dependency.* files from root directory to doc/."
    def move
      config = Configuration.config_hash('dependencies_file_dir' => './doc/')
      File.open(Configuration.config_file_path, 'w') do |f|
        f.write YAML.dump(config)
      end

      FileUtils.mkdir_p("doc")
      FileUtils.mv(Dir["dependencies.*"], "doc")
      say "Congratulations, you have cleaned up your root directory!'", :green
    end

    desc "action_items", "List unapproved dependencies"
    def action_items
      unapproved = Dependency.unapproved

      if unapproved.count == 0
        say "All gems are approved for use", :green
      else
        say "Dependencies that need approval:", :red
        say TextReport.new(unapproved)
        exit 1
      end
    end

    class Dependencies < Thor
      desc "add LICENSE DEPENDENCY_NAME [VERSION]", "Add a dependency that is not managed by Bundler"
      def add(license, name, version = nil)
        Dependency.create_non_bundler(license, name, version)
        say "The #{name} dependency has been added!", :green

        Reporter.write_reports
      rescue LicenseFinder::Error => e
        say e.message, :red
      end

      desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by Bundler"
      def remove(name)
        Dependency.destroy_non_bundler(name)
        say "The #{name} dependency has been removed.", :green

        Reporter.write_reports
      rescue LicenseFinder::Error => e
        say e.message, :red
      end
    end

    desc "dependencies SUBCOMMAND ...ARGS", "manual add and manage non bundler dependencies"
    subcommand "dependencies", Dependencies

    private

    def spinner
      if options[:quiet]
        yield
      else
        begin
          thread = Thread.new {
            wheel = '\|/-'
            i = 0
            while true do
              print "\r ---------- #{wheel[i]} ----------"
              i = (i + 1) % 4
            end
          }
          yield
        ensure
          if thread
            thread.kill
            puts "\r" + " "*24
          end
        end
      end
    end
  end
end<commit_msg>Clarify usage of `license_finder dependencies`<commit_after>require 'thor'

module LicenseFinder
  class CLI < Thor
    option :quiet, type: :boolean, aliases: :q
    desc "rescan", "Find new dependencies."
    def rescan
      spinner {
        BundleSyncer.sync!
        Reporter.write_reports
      }

      action_items
    end
    default_task :rescan

    desc "approve DEPENDENCY_NAME", "Approve a dependency by name."
    def approve(name)
      dependency = Dependency.first(name: name)
      dependency.approve!

      say "The #{dependency.name} dependency has been approved!", :green

      Reporter.write_reports
    end

    desc "license LICENSE DEPENDENCY_NAME", "Update a dependency's license."
    def license(license, name)
      dependency = Dependency.first(name: name)
      dependency.set_license_manually license

      say "The #{name} dependency has been marked as using #{license} license!", :green

      Reporter.write_reports
    end

    desc "move", "Move dependency.* files from root directory to doc/."
    def move
      config = Configuration.config_hash('dependencies_file_dir' => './doc/')
      File.open(Configuration.config_file_path, 'w') do |f|
        f.write YAML.dump(config)
      end

      FileUtils.mkdir_p("doc")
      FileUtils.mv(Dir["dependencies.*"], "doc")
      say "Congratulations, you have cleaned up your root directory!'", :green
    end

    desc "action_items", "List unapproved dependencies"
    def action_items
      unapproved = Dependency.unapproved

      if unapproved.count == 0
        say "All gems are approved for use", :green
      else
        say "Dependencies that need approval:", :red
        say TextReport.new(unapproved)
        exit 1
      end
    end

    class Dependencies < Thor
      desc "add LICENSE DEPENDENCY_NAME [VERSION]", "Add a dependency that is not managed by Bundler"
      def add(license, name, version = nil)
        Dependency.create_non_bundler(license, name, version)
        say "The #{name} dependency has been added!", :green

        Reporter.write_reports
      rescue LicenseFinder::Error => e
        say e.message, :red
      end

      desc "remove DEPENDENCY_NAME", "Remove a dependency that is not managed by Bundler"
      def remove(name)
        Dependency.destroy_non_bundler(name)
        say "The #{name} dependency has been removed.", :green

        Reporter.write_reports
      rescue LicenseFinder::Error => e
        say e.message, :red
      end
    end

    desc "dependencies [add|remove]", "manage non-Bundler dependencies - see `license_finder dependencies help` for more information"
    subcommand "dependencies", Dependencies

    private

    def spinner
      if options[:quiet]
        yield
      else
        begin
          thread = Thread.new {
            wheel = '\|/-'
            i = 0
            while true do
              print "\r ---------- #{wheel[i]} ----------"
              i = (i + 1) % 4
            end
          }
          yield
        ensure
          if thread
            thread.kill
            puts "\r" + " "*24
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09316569954867827, 'fraction_numerical': 0.002256608639587363, 'mean_word_length': 2.157760814249364, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2100677', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1690, 'n_words': 555}