Class: SocialSnippet::CommandLine::SSpm::SubCommands::InstallCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/social_snippet/command_line/sspm/sub_commands/install_command.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #input_stream, #opt_parser, #options, #output_stream, #streams, #tokens

Instance Method Summary collapse

Methods inherited from Command

#define_option, #init, #initialize, #social_snippet

Constructor Details

This class inherits a constructor from SocialSnippet::CommandLine::Command

Instance Method Details

#define_optionsObject


30
31
32
33
# File 'lib/social_snippet/command_line/sspm/sub_commands/install_command.rb', line 30

def define_options
  define_option :dry_run, :type => :flag, :short => true, :default => false
  define_option :name, :short => true, :default => nil
end

#descObject


26
27
28
# File 'lib/social_snippet/command_line/sspm/sub_commands/install_command.rb', line 26

def desc
  "Install snippet repository"
end

#install_by_namesObject


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/social_snippet/command_line/sspm/sub_commands/install_command.rb', line 50

def install_by_names
  while has_next_token?
    token_str = next_token
    if is_name?(token_str)
      repo_info = parse_repo_token(token_str)
      social_snippet.api.install_repository_by_name repo_info[:name], repo_info[:ref], options
    elsif is_url?(token_str)
      repo_info = parse_repo_token(token_str)
      repo_url  = repo_info[:name]
      social_snippet.api.install_repository_by_url repo_url, repo_info[:ref], options
    elsif is_path?(token_str)
      repo_info = parse_repo_token(token_str)
      repo_path = repo_info[:name]
      social_snippet.api.install_repository_by_path repo_path, repo_info[:ref], options
    end
  end
end

#install_by_snippet_jsonObject


43
44
45
46
47
48
# File 'lib/social_snippet/command_line/sspm/sub_commands/install_command.rb', line 43

def install_by_snippet_json
  snippet_json = ::JSON.parse(File.read("snippet.json"))
  snippet_json["dependencies"].each do |name, ref|
    social_snippet.api.install_repository_by_name name, ref, options
  end
end

#runObject


35
36
37
38
39
40
41
# File 'lib/social_snippet/command_line/sspm/sub_commands/install_command.rb', line 35

def run
  if has_next_token?
    install_by_names
  else
    install_by_snippet_json
  end
end

#usageObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/social_snippet/command_line/sspm/sub_commands/install_command.rb', line 9

def usage
  <<EOF
Usage: sspm install [options] [--] <repo> [<repo> ...]

<repo>'s format:
    <name> (e.g. "example-repo")
    <name>#<version> (e.g. "example-repo#0.0.1")

Example:
$ sspm install example-repo
-> Installed latest version (or remote's current ref)

$ sspm install example-repo#0.0.1
-> Installed as the specified version
EOF
end