Class: Sutty::Cli::Commands::Post

Inherits:
Sutty::Cli::Command show all
Defined in:
lib/sutty/cli/commands/post.rb

Constant Summary collapse

CONTENT_FIELDS =
%w[content markdown_content].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Sutty::Cli::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(options) ⇒ Post

Returns a new instance of Post.



19
20
21
22
# File 'lib/sutty/cli/commands/post.rb', line 19

def initialize(options)
  @options = options.to_h
  @options['title'] ||= random_string(10)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/sutty/cli/commands/post.rb', line 15

def options
  @options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sutty/cli/commands/post.rb', line 24

def execute(input: $stdin, output: $stdout)
  if File.exist? path
    logger.info "The file #{path} already exists"
    return true
  end

  TTY::File.create_file path,
                        YAML.dump(data) +
                        "---\n\n" +
                        (content? ? random_markdown : '')
end