Class: Jank::JankCommand

Inherits:
Command show all
Defined in:
lib/jank_command.rb

Instance Method Summary collapse

Methods inherited from Command

#dispatch, #initialize

Constructor Details

This class inherits a constructor from Jank::Command

Instance Method Details

#config_commandObject



5
6
7
# File 'lib/jank_command.rb', line 5

def config_command
  puts @config.to_yaml
end

#config_help_textObject



93
94
95
96
97
98
99
# File 'lib/jank_command.rb', line 93

def config_help_text
"usage: jank config\n\nDisplays the jank configuration for the current directory.\n"
end

#gopath_commandObject



18
19
20
# File 'lib/jank_command.rb', line 18

def gopath_command
  puts @config.env['GOPATH']
end

#gopath_help_textObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/jank_command.rb', line 101

def gopath_help_text
"usage: jank path\n\nDisplays additional gopaths for this directory. Paths can\nbe added by placing .jank files in directories with the\nkey 'gopath'. The gopath key can map to a string or an array\nof additional gopaths. Gopaths are scanned for in this manner\nup the filesystem until the user's home directory.\n\nGopaths specified in the .jank file can be either absolute\npaths or paths relative to the directory.\n"
end

#helpObject



9
10
11
12
13
14
15
16
# File 'lib/jank_command.rb', line 9

def help
  topic_help = "#{@args[1]}_help_text"
  if self.respond_to? topic_help
    puts self.send(topic_help)
  else
    puts jank_help_text
  end
end

#jank_help_textObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/jank_command.rb', line 70

def jank_help_text
"Jank - the janky gopath tool.\n\nUsage:\n\n  jank command [arguments]\n\nThe commands are:\n\nconfig      show the jank configuration for the directory\ngopath      displays gopath for the directory\nhelp        show this!\nlink        link a go-gettable source tree into the gopath\npackage     displays the package for the current directory\nstat        lists packages linked into gopath\nsync        syncs packages linked into gopath\nunlink      unlink a go-gettable source tree from the gopath\n\nUse \"jank help [command]\" for more information about a command.\n"
end


22
23
24
# File 'lib/jank_command.rb', line 22

def link_command
  puts "Package #{@config.package || '[UNKNOWN]'} is not jankable" if !@janker.link
end


116
117
118
119
120
121
122
123
124
125
# File 'lib/jank_command.rb', line 116

def link_help_text
"usage: jank link\n\nFor packages developed in a go-gettable stlye outside the\ngopath, invoking link will link the package into the gopath.\nThis requires that the directory or some parent contains a\n.jank file with the 'package' key set to go package name.\n"
end

#package_commandObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/jank_command.rb', line 26

def package_command
  if ARGV[1] == '-r' || ARGV[1] == '--reverse'
    package = ARGV[2]
    if package == nil
      STDERR.puts puts package_help_text
      exit(1)
    end

    @janker.sync_packages
    puts @janker.location_of_package(package)
    exit
  end

  path = ARGV[1]
  if path == nil
    puts @config.package
    exit
  end

  @janker.sync_packages
  puts @janker.package_for_location path
end

#package_help_textObject



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/jank_command.rb', line 127

def package_help_text
"usage: jank package [flags] [path]\n\nFlags:\n-r, --reverse\n              Return directory for go package\n\nDisplays the package for the current directory or the path\nif specified. Specifiying the reverse flag returns the\nfilesystem path of a go package.\n"
end

#stat_commandObject



49
50
51
52
53
54
# File 'lib/jank_command.rb', line 49

def stat_command
  @janker.sync_packages
  @janker.walk_janked_packages do |package, local_path, go_path|
    puts "#{package} --> #{local_path}"
  end
end

#stat_help_textObject



141
142
143
144
145
146
147
148
# File 'lib/jank_command.rb', line 141

def stat_help_text
"usage: jank stat\n\nDisplays a mapping of packages in the gopath that are linked\nto go-gettable source trees that reside outside of the gopath.\n"
end

#sync_commandObject



56
57
58
# File 'lib/jank_command.rb', line 56

def sync_command
  @janker.sync_packages
end

#sync_help_textObject



150
151
152
153
154
155
156
# File 'lib/jank_command.rb', line 150

def sync_help_text
"usage: jank sync\n\nSyncs all packages linked into the gopath.\n"
end


60
61
62
63
64
65
66
67
68
# File 'lib/jank_command.rb', line 60

def unlink_command
  all = @args[1] == '-a' || @args[1] == '--all'

  if all
    @janker.unlink_all
  else
    puts "Package #{@config.package || '[UNKNOWN]'} is not jankable" if !@janker.unlink
  end
end


158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/jank_command.rb', line 158

def unlink_help_text
"usage: jank unlink [flags]\n\nFlags:\n-a, --all\n              Unlink all linked packages\n\nFor packages developed in a go-gettable stlye outside the\ngopath, invoking unlink will remove the package from the\ngopath. This requires that the directory or some parent\ncontains a .jank file with the 'package' key set to go\npackage name.\n"
end