Sha256: 3ef3667fa9dff23dd5acd6dbdcbdce38597c3b641305bc1a650a5bf326fa8649

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module I18nJS
  class CLI
    class InitCommand < Command
      command_name "init"
      description "Initialize a project"

      parse do |opts|
        opts.banner = "Usage: i18n #{name} [options]"

        opts.on(
          "-cCONFIG_FILE",
          "--config=CONFIG_FILE",
          "The configuration file that will be generated"
        ) do |config_file|
          options[:config_file] = config_file
        end

        opts.on("-h", "--help", "Prints this help") do
          ui.exit_with opts.to_s
        end
      end

      command do
        file_path = File.expand_path(options[:config_file])

        if File.file?(file_path)
          ui.fail_with("ERROR: #{file_path} already exists!")
        end

        FileUtils.mkdir_p(File.dirname(file_path))

        File.open(file_path, "w") do |file|
          file << <<~YAML
            ---
            translations:
              - file: app/javascript/locales.json
                patterns:
                  - "*"
                  - "!*.activerecord"
                  - "!*.errors"
                  - "!*.number.nth"

          YAML
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i18n-js-4.0.0.alpha2 lib/i18n-js/cli/init_command.rb
i18n-js-4.0.0.alpha1 lib/i18n-js/cli/init_command.rb