Class: WikiTipsPost::HelperCommand

Inherits:
Mothership
  • Object
show all
Defined in:
lib/wiki_tips_post/helper_command.rb

Instance Method Summary collapse

Instance Method Details

#helpObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/wiki_tips_post/helper_command.rb', line 9

def help
  if name = input[:command]
    if cmd = @@commands[name.gsub("-", "_").to_sym]
      Mothership::Help.command_help(cmd)
    else
      unknown_command(name)
    end
  else
    Mothership::Help.basic_help(@@commands, @@global)
  end
end

#postObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wiki_tips_post/helper_command.rb', line 26

def post
  begin
    tag_array = input[:tags].split(',')
  rescue StandardError => e
    puts "Wrong tag format, it should be string split with ,"
  end

  tip_content = nil
  if input[:file]
    tip_content = File.read File.expand_path(input[:file])
  end

  @wikiposter = WikiPostHelper.new(
    :title => input[:title],
    :tips => tip_content || input[:tip],
    :tags => tag_array
  )

  puts "\ncloning repo..."
  @wikiposter.prepare_repo

  puts "\ncreating post..."
  @wikiposter.create_post

  puts "\npushing repo..."
  push_repo_success = @wikiposter.push_to_repo

  if push_repo_success
    puts "\nremoving temporary clone of repo..."
    @wikiposter.delete_local_repo_clone

    puts "\nsuccessfully added tip!"
  else
    puts "\npush was NOT successful"

    exit 1
  end
end