summaryrefslogtreecommitdiff
path: root/lib/leap_cli/commands
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-28 20:14:05 -0800
committerelijah <elijah@riseup.net>2012-11-28 20:14:05 -0800
commite5ed1ba2df6f735e32de35d9171d572dce322b7f (patch)
tree1a9120599adc7215edee5cf36ef27511823dd819 /lib/leap_cli/commands
parente2c31618b6f70d86c55c348436dd600b2e4ace21 (diff)
new system for how directory paths work. now there is a file Leapfile that manages this, instead of it always being ../leap_platform
Diffstat (limited to 'lib/leap_cli/commands')
-rw-r--r--lib/leap_cli/commands/node.rb5
-rw-r--r--lib/leap_cli/commands/pre.rb24
-rw-r--r--lib/leap_cli/commands/project.rb121
3 files changed, 115 insertions, 35 deletions
diff --git a/lib/leap_cli/commands/node.rb b/lib/leap_cli/commands/node.rb
index 678bebd..aa9610f 100644
--- a/lib/leap_cli/commands/node.rb
+++ b/lib/leap_cli/commands/node.rb
@@ -6,11 +6,13 @@ module LeapCli; module Commands
##
## COMMANDS
##
+
desc 'Node management'
command :node do |c|
c.desc 'Create a new configuration file for a node'
c.command :add do |c|
c.action do |global_options,options,args|
+ log 'not yet implemented'
end
end
@@ -34,6 +36,7 @@ module LeapCli; module Commands
c.desc 'Renames a node file, and all its related files'
c.command :mv do |c|
c.action do |global_options,options,args|
+ log 'not yet implemented'
end
end
@@ -41,7 +44,7 @@ module LeapCli; module Commands
c.arg_name '<node-name>', :optional => false, :multiple => false
c.command :rm do |c|
c.action do |global_options,options,args|
- remove_file!()
+ log 'not yet implemented'
end
end
end
diff --git a/lib/leap_cli/commands/pre.rb b/lib/leap_cli/commands/pre.rb
index dce01eb..cae787e 100644
--- a/lib/leap_cli/commands/pre.rb
+++ b/lib/leap_cli/commands/pre.rb
@@ -10,11 +10,6 @@ module LeapCli
default_value '1'
flag [:v, :verbose]
- desc 'Specify the root directory'
- arg_name 'path'
- default_value Path.root
- flag [:root]
-
desc 'Display version number and exit'
switch :version, :negatable => false
@@ -30,17 +25,18 @@ module LeapCli
end
#
- # require a root directory
+ # load Leapfile
#
- if global[:root]
- Path.set_root(global[:root])
+ unless LeapCli.leapfile.load
+ bail! { log :missing, 'Leapfile in directory tree' }
end
- if Path.ok?
- true
- else
- bail! do
- log :error, "- Could not find the root directory. Change current working directory or try --root"
- end
+ Path.set_platform_path(LeapCli.leapfile.platform_directory_path)
+ Path.set_provider_path(LeapCli.leapfile.provider_directory_path)
+ if !Path.provider || !File.directory?(Path.provider)
+ bail! { log :missing, "provider directory '#{Path.provider}'" }
+ end
+ if !Path.platform || !File.directory?(Path.platform)
+ bail! { log :missing, "platform directory '#{Path.platform}'" }
end
#
diff --git a/lib/leap_cli/commands/project.rb b/lib/leap_cli/commands/project.rb
index c748128..2f36bc5 100644
--- a/lib/leap_cli/commands/project.rb
+++ b/lib/leap_cli/commands/project.rb
@@ -1,25 +1,106 @@
-module LeapCli
- module Commands
-
- desc 'Creates a new provider directory.'
- arg_name '<directory>'
- skips_pre
- command :'init-provider' do |c|
- c.action do |global_options,options,args|
- directory = args.first
- unless directory && directory.any?
- help! "Directory name is required."
- end
- directory = File.expand_path(directory)
- if File.exists?(directory)
- raise "#{directory} already exists."
- end
- if agree("Create directory '#{directory}'? ")
- LeapCli.init(directory)
+require 'fileutils'
+
+module LeapCli; module Commands
+
+ desc 'Initializes a new LEAP provider in the specified directory.'
+ arg_name 'directory-path'
+ skips_pre
+ command :init do |c|
+ c.flag 'name', :desc => "The name of the provider", :default_value => 'Example'
+ c.flag 'domain', :desc => "The primary domain of the provider", :default_value => 'example.org'
+ c.flag 'platform', :desc => "File path of the leap_platform directory", :default_value => '../leap_platform'
+ c.action do |global_options, options, args|
+ directory = args.first
+ unless directory && directory.any?
+ help! "Directory name is required."
+ end
+ directory = File.expand_path(directory)
+ unless File.exists?(directory)
+ bail! { log :missing, "directory #{directory}" }
+ end
+ create_initial_provider_files(directory, options)
+ end
+ end
+
+ private
+
+ DEFAULT_REPO = 'git://leap.se/leap_platform' # TODO: use https
+
+ #
+ # creates new provider directory
+ #
+ def create_initial_provider_files(directory, options)
+ Path.set_provider_path(directory)
+ Dir.chdir(directory) do
+ assert_files_missing! 'provider.json', 'common.json', 'Leapfile', :base => directory
+
+ platform_dir = File.expand_path(options[:platform])
+
+ unless File.symlink?(platform_dir) || File.directory?(platform_dir)
+ if agree("The platform directory \"#{options[:platform]}\" does not exist.\nDo you want me to create it by cloning from the\ngit repository #{DEFAULT_REPO}? ")
+ assert_bin! 'git'
+ ensure_dir platform_dir
+ Dir.chdir(platform_dir) do
+ log :cloning, "leap_platform into #{platform_dir}"
+ pty_run "git clone --branch develop #{DEFAULT_REPO} ."
+ pty_run 'git submodule update --init'
+ end
else
- puts "OK, bye."
+ bail!
end
end
+ write_file! '.gitignore', GITIGNORE_CONTENT
+ write_file! 'provider.json', provider_content(options)
+ write_file! 'common.json', COMMON_CONTENT
+ write_file! 'Leapfile', leapfile_content(options)
+ ["nodes", "services", "tags"].each do |dir|
+ ensure_dir dir
+ end
+ log :completed, 'initialization'
end
end
-end \ No newline at end of file
+
+ def leapfile_content(options)
+ %[@platform_directory_path = "#{options[:platform]}"
+]
+ # leap_version = "#{LeapCli::VERSION}"
+ # platform_version = ""
+ end
+
+ GITIGNORE_CONTENT = <<EOS
+test/Vagrantfile
+test/.vagrant
+test/openvpn
+test/cert
+EOS
+
+ def provider_content(options)
+ %[#
+# General service provider configuration.
+#
+{
+ "domain": "#{options[:domain]}",
+ "name": {
+ "en": "#{options[:name]}"
+ },
+ "description": {
+ "en": "You really should change this text"
+ },
+ "languages": ["en"],
+ "default_language": "en",
+ "enrollment_policy": "open"
+}
+]
+ end
+
+ COMMON_CONTENT = <<EOS
+#
+# Options put here are inherited by all nodes.
+#
+{
+}
+EOS
+
+end; end
+
+