Class: Hylite::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/hylite/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(stdin, argv) ⇒ CLI

Returns a new instance of CLI.



30
31
32
33
# File 'lib/hylite/cli.rb', line 30

def initialize(stdin, argv)
  self.stdin = stdin
  self.argv = argv
end

Instance Method Details

#configObject



51
52
53
# File 'lib/hylite/cli.rb', line 51

def config
  @config ||= parse(argv)
end

#errorsObject



47
48
49
# File 'lib/hylite/cli.rb', line 47

def errors
  config.fetch :errors
end

#help_screenObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hylite/cli.rb', line 5

def help_screen
  <<-HELP
  Usage: echo '1+1' | hylite

    Syntax Highlighting for Scripters.

    Finds an existing syntax highlighting tool (rouge, coderay, pygments),
    and uses that to highlight the code.

  Options:
    -h        This help screen
    -l LANG   Set the language (defaults to Ruby)

  Examples:
    Set the language to JavaScript
    $ echo 'function alphabet() { console.log("abc"); }' | hylite -l javascript

    Add syntax highlighting to `cat`
    $ cat lib/hylite.rb | hylite

    Highlight sassy style sheets
    $ cat app/assets/stylesheets/site.css.scss | hylite -l scss
  HELP
end

#resultObject



35
36
37
38
39
# File 'lib/hylite/cli.rb', line 35

def result
  return help_screen if config[:help]
  ensure_evaluated
  @result
end

#success?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/hylite/cli.rb', line 41

def success?
  return true if config[:help]
  ensure_evaluated
  errors.none?
end