Class: TaskLoop::Command

Inherits:
CLAide::Command
  • Object
show all
Defined in:
lib/taskloop/command.rb

Direct Known Subclasses

Deploy, Env, Init, Launch, List, Log, Run, Shutdown, Undeploy

Constant Summary collapse

LOGO =
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@          @@@@@@@@@@@@@@@@@@@@@@   @@@@@@@    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@    @@@@@@    @@@@@       @@@   @@   @@    @@@@@      @@@@      @@@       @@@@@@@@@\n@@@@@@@@@@@    @@@@   @@   @@   @@@   @@   @   @@@    @@@@   @@   @@   @@   @@   @@   @@@@@@@@\n@@@@@@@@@@@    @@@@@@@@@   @@@    @@@@@@      @@@@    @@@@   @@   @@   @@   @@   @@   @@@@@@@@\n@@@@@@@@@@@    @@@@        @@@@@@    @@@      @@@@    @@@@   @@   @@   @@   @@   @@   @@@@@@@@\n@@@@@@@@@@@    @@@   @@@   @@   @@@   @@   @   @@@    @@@@   @@   @@   @@   @@   @@   @@@@@@@@\n@@@@@@@@@@@    @@@@        @@@       @@@   @@   @@      @@@      @@@@      @@@       @@@@@@@@@\n@@@@@@@@@@@    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   @@@@@@@@@@@@@\n@@@@@@@@@@@   @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
DOLPHIN =
"\n                   (@&/////%@@@@@@@@@@@@@#                                  \n                      @@&@&////////////////(@@#                             \n                     /@(///////////////////////%@/                          \n                   *@////////////////////////////\#@,                        \n                  @&///////////////////////////////@%                       \n                 @&//////////////(@////@&#/////////(@                       \n                 @////////////@@  @////@    ,.@////@@                       \n                /@//////////&@  ,@@////@@@&.  *///@@                        \n                ,@/////////(@@@   @///&@     /@@///@@                       \n                 @%////////@@     @@@&           @@/@#                      \n                  @#///////@           ,                                    \n                   @@//////@&      @(//@                                    \n                     @@/////%@    @////@                                    \n                        @@/////\#@@@////@                                    \n                            &@@@&#((&@@                                     \n                      /&#         @///@@                                    \n                   ,///,*.        @////@                                    \n               &#  %/,@           @@///@                                    \n             (, .*/&*%/*%///&       (@@@         ,*/////*.                  \n       %/\#@, ////&  @  % .&  /@%/(/    /#/\#@(                 \#@#/&         \n    (/&               .           .////,                           &//      \n   &(//@                         &//////&                         @///@     \n     (@%//////#&@@@@@@@@@@%///////@@  @@///////%@@@@@@@@@@&#//////\#@#       \n            %@@@@&@@@@@&&@@@@/              /@@@@&&@@@@@&@@@@&\n"

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.



26
27
28
29
# File 'lib/taskloop/command.rb', line 26

def initialize(argv)
  # @verbose = argv.flag?('verbose', true)
  super
end

Instance Method Details

#create_dir_if_needed(dir) ⇒ Object



62
63
64
65
66
# File 'lib/taskloop/command.rb', line 62

def create_dir_if_needed(dir)
  unless File.directory?(dir)
    FileUtils.mkdir(dir)
  end
end

#create_file_if_needed(path) ⇒ Object



57
58
59
60
61
# File 'lib/taskloop/command.rb', line 57

def create_file_if_needed(path)
  unless File.file?(path)
    File.new(path, "w")
  end
end

#create_taskloop_file_structure_if_neededObject

Path and Directory and Files



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/taskloop/command.rb', line 38

def create_taskloop_file_structure_if_needed
  # create ~/.taskloop/ dir
  create_dir_if_needed(taskloop_dir)
  # create ~/.taskloop/projlist file
  unless File.exists?(taskloop_proj_list_path)
    projlist = File.new(taskloop_proj_list_path, "w+")
    projlist.puts "[]"
    projlist.close
  end

  # create ~/.taskloop/crontab file
  create_file_if_needed(taskloop_cron_tab_path)
  # create ~/.taskloop/cronlog file
  create_file_if_needed(taskloop_cron_log_path)

  # create ~/.taskloop/data/ dir
  create_dir_if_needed(taskloop_data_dir)
end

#runObject



31
32
33
# File 'lib/taskloop/command.rb', line 31

def run
  create_taskloop_file_structure_if_needed
end

#taskloop_cron_log_pathObject



76
77
78
# File 'lib/taskloop/command.rb', line 76

def taskloop_cron_log_path
  File.join(taskloop_dir, "cronlog")
end

#taskloop_cron_tab_pathObject



80
81
82
# File 'lib/taskloop/command.rb', line 80

def taskloop_cron_tab_path
  File.join(taskloop_dir, "crontab")
end

#taskloop_data_dirObject



92
93
94
# File 'lib/taskloop/command.rb', line 92

def taskloop_data_dir
  File.join(taskloop_dir, "data")
end

#taskloop_data_proj_dirsObject



102
103
104
105
106
107
108
109
110
111
# File 'lib/taskloop/command.rb', line 102

def taskloop_data_proj_dirs
  dirs = Dir.entries(taskloop_data_dir)
  result = []
  dirs.each do |dir|
    if dir != '.' && dir != '..'
      result.push(dir)
    end
  end
  return result
end

#taskloop_dirObject



72
73
74
# File 'lib/taskloop/command.rb', line 72

def taskloop_dir
  File.join(Dir.home, ".taskloop")
end

#taskloop_environments_pathObject



84
85
86
# File 'lib/taskloop/command.rb', line 84

def taskloop_environments_path
  File.join(taskloop_dir, "environments")
end

#taskloop_proj_list_dirsObject



96
97
98
99
100
# File 'lib/taskloop/command.rb', line 96

def taskloop_proj_list_dirs
  json_string = File.read(taskloop_proj_list_path)
  parsed_json = JSON.parse(json_string)
  return parsed_json
end

#taskloop_proj_list_pathObject



88
89
90
# File 'lib/taskloop/command.rb', line 88

def taskloop_proj_list_path
  File.join(taskloop_dir, "projlist")
end

#taskloop_taskfile_pathsObject



113
114
115
116
117
118
119
120
# File 'lib/taskloop/command.rb', line 113

def taskloop_taskfile_paths
  paths = taskloop_data_proj_dirs
  result = []
  paths.each do |path|
    result.push(File.join(path, ".Taskfile.deploy"))
  end
  return result
end

#tasklooprc_pathObject



68
69
70
# File 'lib/taskloop/command.rb', line 68

def tasklooprc_path
  File.join(Dir.home, ".tasklooprc")
end