<commit_before>
require 'thor'

module Kitchenplan
  class Cli < Thor
    include Thor::Actions

    desc 'setup [<GITREPO>] [<TARGET DIRECTORY>]', 'setup Kitchenplan'
    def setup(gitrepo=nil, targetdir='/opt')
      logo
      install_clt unless File.exists?("/usr/bin/cc")
      if gitrepo
        fetch(gitrepo, targetdir)
      else
        has_config = yes?('Do you have a config repository? [y,n]', :green)
        if has_config
          gitrepo = ask('Please enter the clone URL of your git config repository:', :green)
          fetch(gitrepo, targetdir)
        else
          create(targetdir)
        end
      end
      unless File.exists?("#{targetdir}/kitchenplan/config/people/#{ENV['USER']}.yml")
        user_create = yes?("config/people/#{ENV['USER']}.yml does not exist. Do you wish to create it? [y,n]", :green)
        if user_create
          create_user(targetdir)
        end
      end
    end

    option :debug, :type => :boolean
    option :recipes, :type => :array
    desc 'provision [<TARGET DIRECTORY>] [--debug] [--recipes=x y z]', 'run Kitchenplan, using debug will show more command output'
    def provision(targetdir='/opt')
      logo
      prepare_folders(targetdir)
      install_bundler(targetdir)
      send_ping
      recipes = parse_config(targetdir)
      fetch_cookbooks(targetdir, options[:debug])
      run_chef(targetdir, (options[:recipes] ? options[:recipes] : recipes), options[:debug])
      cleanup(targetdir, options[:debug])<commit_msg>Add some more documentation<commit_after>
require 'thor'

module Kitchenplan
  class Cli < Thor
    include Thor::Actions

    desc 'setup [<gitrepo>] [<target directory>]', 'Setup your workstation to run Kitchenplan and create an example configuration'
    long_desc <<-LONGDESC
    `kitchenplan setup` will install the dependencies of Kitchenplan and create a configuration in /opt/kitchenplan (or <target directory>
    if you pass it along) to use with the `kitchenplan provision` command.

    If you already have a configuration stored in git somewhere, it will ask you to pass the git repo url. If you want to bypass the
    prompt, pass it along on the commandline. (see .travis.yml for an example)
    LONGDESC
    def setup(gitrepo=nil, targetdir='/opt')
      logo
      install_clt unless File.exists?("/usr/bin/cc")
      if gitrepo
        fetch(gitrepo, targetdir)
      else
        has_config = yes?('Do you have a config repository? [y,n]', :green)
        if has_config
          gitrepo = ask('Please enter the clone URL of your git config repository:', :green)
          fetch(gitrepo, targetdir)
        else
          create(targetdir)
        end
      end
      unless File.exists?("#{targetdir}/kitchenplan/config/people/#{ENV['USER']}.yml")
        user_create = yes?("config/people/#{ENV['USER']}.yml does not exist. Do you wish to create it? [y,n]", :green)
        if user_create
          create_user(targetdir)
        end
      end
    end

    option :debug, :type => :boolean
    option :recipes, :type => :array
    desc 'provision [<target directory>] [--debug] [--recipes=x y z]', 'Provision your workstation with Kitchenplan'
    long_desc <<-LONGDESC
    `kitchenplan provision` will use the configuration in /opt/kitchenplan (or <target directory>
    if you pass it along) to provision your workstation using Chef.

    You can optionally pass --debug to see more detail of what's happeling.

    If you just want to install a few recipes pass them along with --recipes and it will override the run list (not the attributes!)
    LONGDESC
    def provision(targetdir='/opt')
      logo
      prepare_folders(targetdir)
      install_bundler(targetdir)
      send_ping
      recipes = parse_config(targetdir)
      fetch_cookbooks(targetdir, options[:debug])
      run_chef(targetdir, (options[:recipes] ? options[:recipes] : recipes), options[:debug])
      cleanup(targetdir, options[:debug])
{'fraction_non_alphanumeric': 0.10486128785950624, 'fraction_numerical': 0.0, 'mean_word_length': 3.059917355371901, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '7354055', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1113, 'n_words': 380}