Sha256: 1e65015889755fcb82ccb42f94d0d43cffeb18ecfbe00deb570ce4483954d5af

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require "thor"

require_relative "../tns"

module TNS
  # CLI to generate stuff
  class CLI < Thor
    desc "generate <color>", "Generate tints and shades from a given color"
    long_desc <<~LONGDESC
      Tints 'N Shades (tns) is a tints and shades generator for command line
      lovers. Generate palettes in CSS/SASS/Tailwind based on a Hex color.

        tns g #ff7d00
        --primary-100: #ffe5cc;
        --primary-200: #ffcb99;
    LONGDESC

    option :name, default: "primary",
                  type: :string,
                  aliases: "-n",
                  desc: "The name of your color"
    option :output, default: "css",
                    enum: %w[css sass tailwind],
                    type: :string,
                    aliases: "-o",
                    desc: "The output format"
    option "color-format", default: "hex",
                           enum: %w[hex hsl rgb],
                           type: :string,
                           aliases: "-c",
                           desc: "The color format to use. "
    def generate(color)
      rgb = Color::RGB.from_hex(color)
      name = options["name"]
      color_format = options["color-format"]
      output = options["output"]
      palette = Palette.new(rgb).to(color_format)
      output = Output.from_argument(output, name)
      puts output.format(palette)
    rescue ArgumentError => e
      # Wrap argument errors into thor errors for nicer reporting to user
      raise Thor::Error, e.message
    end

    map "g" => :generate

    def self.exit_on_failure?
      true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tints-n-shades-0.1.0 lib/tns/cli.rb