Class: PgxnUtils::CLI

Inherits:
Thor
  • Object
show all
Includes:
NoTasks, Thor::Actions
Defined in:
lib/pgxn_utils/cli.rb

Constant Summary

Constants included from Constants

PgxnUtils::Constants::UPLOAD_URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NoTasks

#ask_for_pgxn_credential, #can_zip?, #check_response, #config_options, #has_scm?, #init_repository, #is_dir?, #is_dirty?, #is_extension?, #make_dist_clean, #prepare_multipart_post_for, #resolve_extension_path_and_name, #scm_archive, #selected_template, #send_file_to_pgxn, #set_accessors, #try_send_file, #zip_archive

Instance Attribute Details

#abstractObject

Returns the value of attribute abstract.



4
5
6
# File 'lib/pgxn_utils/cli.rb', line 4

def abstract
  @abstract
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/pgxn_utils/cli.rb', line 4

def description
  @description
end

#extension_nameObject

, :maintainer_mail



3
4
5
# File 'lib/pgxn_utils/cli.rb', line 3

def extension_name
  @extension_name
end

#generated_byObject

Returns the value of attribute generated_by.



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

def generated_by
  @generated_by
end

#licenseObject

Returns the value of attribute license.



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

def license
  @license
end

#maintainerObject

, :maintainer_mail



3
4
5
# File 'lib/pgxn_utils/cli.rb', line 3

def maintainer
  @maintainer
end

#pgxn_passwordObject

Returns the value of attribute pgxn_password.



6
7
8
# File 'lib/pgxn_utils/cli.rb', line 6

def pgxn_password
  @pgxn_password
end

#pgxn_usernameObject

Returns the value of attribute pgxn_username.



6
7
8
# File 'lib/pgxn_utils/cli.rb', line 6

def pgxn_username
  @pgxn_username
end

#release_statusObject

Returns the value of attribute release_status.



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

def release_status
  @release_status
end

#tagsObject

Returns the value of attribute tags.



4
5
6
# File 'lib/pgxn_utils/cli.rb', line 4

def tags
  @tags
end

#targetObject

, :maintainer_mail



3
4
5
# File 'lib/pgxn_utils/cli.rb', line 3

def target
  @target
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/pgxn_utils/cli.rb', line 4

def version
  @version
end

Class Method Details

.source_rootObject



123
124
125
# File 'lib/pgxn_utils/cli.rb', line 123

def self.source_root
  @_source_root ||= File.expand_path('../templates', __FILE__)
end

Instance Method Details

#bundle(extension_name = ".") ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/pgxn_utils/cli.rb', line 83

def bundle(extension_name=".")
     unless is_extension?(extension_name)
       say "'#{extension_name}' doesn't appears to be an extension. Please, supply the extension's name", :red
     else
       path = File.expand_path(extension_name)
       extension_name = File.basename(path)

       self.target = path
       archive_name = "#{path}-#{config_options['version']}"
	prefix_name  = "#{extension_name}-#{config_options['version']}/"

	archive = "#{archive_name}.zip"
	archived = false

	if has_scm?(path)
		if is_dirty?(path)
			say "Your repository is dirty! You should commit or stash before continue.", :red
		else
			if can_zip?(archive)
				scm_archive(path, archive, prefix_name)
				archived = true
			end
		end
	else
		if can_zip?(archive)
			make_dist_clean(path)
			zip_archive(path, archive, prefix_name)
			archived = true
		end
	end
	say_status(:create, archive, :green) if archived
  end
end

#change(extension_name = ".") ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/pgxn_utils/cli.rb', line 63

def change(extension_name=".")
  extension_path, extension_name = resolve_extension_path_and_name(extension_name)

	  template_type = File.read("#{extension_path}/.template").chomp

  self.target = extension_path
  self.extension_name = extension_name

  set_accessors(extension_name)

  if is_extension?(extension_path)
    template "#{template_type}/META.json.tt", "#{extension_path}/META.json"
    template "#{template_type}/%extension_name%.control.tt", "#{extension_path}/%extension_name%.control"
  else
    say "'#{extension_name}' doesn't appears to be an extension. Please, supply the extension's name", :red
  end
end

#release(filename) ⇒ Object



119
120
121
# File 'lib/pgxn_utils/cli.rb', line 119

def release(filename)
  send_file_to_pgxn(filename)
end

#skeleton(extension_name, target = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pgxn_utils/cli.rb', line 29

def skeleton(extension_name,target=nil)
  self.target = options[:target] || target || "."

  if is_extension?("#{self.target}/#{extension_name}")
    say "'#{extension_name}' already exists. Please, use 'change' instead 'skeleton'.", :red
  elsif is_extension?(self.target)
    say "You are inside a extension directory, already. Consider use 'change' instead.", :red
  elsif is_dir?("#{self.target}/#{extension_name}")
    say "Can't create an extension overwriting an existing directory.", :red
  else
    self.set_accessors extension_name

    directory selected_template, extension_name

		init_repository("#{self.target}/#{extension_name}") if options[:git]
  end
end