Module: DevContext::Commands::ContextLifecycle
- Included in:
- DevContext::CLI
- Defined in:
- lib/dev_context/commands/context_lifecycle.rb
Instance Method Summary collapse
Instance Method Details
#cmd_activate ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dev_context/commands/context_lifecycle.rb', line 62 def cmd_activate target = argv.shift return usage_error("dx activate CONTEXT|PATH|URL or dx cd CONTEXT|PATH|URL") if blank?(target) context, code = resolve_or_create_context(target) return code unless code.zero? config.activate_context!(context.fetch("name")) script = ShellEmitter.new( context: context, remote_name: env.fetch("DX_GIT_REMOTE_NAME", "USE-REPO"), auto_create_local_branch: truthy?(env.fetch("DX_AUTO_CREATE_LOCAL_BRANCH", "true")) ).activation_script out.write(script) 0 end |
#cmd_add ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dev_context/commands/context_lifecycle.rb', line 6 def cmd_add args = argv.dup opts = parse_common_flags!(args, allow_context: true, allow_norun: true) return usage_error("dx add PATH|URL ...") if args.empty? if opts[:context] && args.length != 1 return usage_error("dx add -c NAME PATH|URL") end exit_code = 0 args.each do |target| code = add_single_target(target, explicit_context: opts[:context], opts: opts) exit_code = code unless code.zero? end exit_code rescue OptionParser::InvalidOption => e err.puts("dx: #{e.}") usage_error("dx add [-c NAME] [-n] [-v] PATH|URL ...") end |
#cmd_clone ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dev_context/commands/context_lifecycle.rb', line 26 def cmd_clone args = argv.dup opts = parse_common_flags!(args, allow_context: true, allow_norun: true) url = args.shift explicit_path = args.shift return usage_error("dx clone URL [PATH]") if blank?(url) return usage_error("dx clone URL [PATH]") unless url?(url) clone_and_register!(url, explicit_path: explicit_path, explicit_name: opts[:context], opts: opts) rescue OptionParser::InvalidOption => e err.puts("dx: #{e.}") usage_error("dx clone [-c NAME] [-n] [-v] URL [PATH]") end |
#cmd_create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dev_context/commands/context_lifecycle.rb', line 40 def cmd_create args = argv.dup opts = parse_common_flags!(args, allow_context: true, allow_norun: true) name = args.shift name = opts[:context] if blank?(name) return usage_error("dx create NAME [PATH] [BRANCH]") if blank?(name) repo_path = args.shift || pwd branch = args.shift || current_branch(repo_path) || "main" if opts[:norun] out.puts("Would create context #{config.normalize_name(name)} -> #{File.(repo_path)} @ #{branch}") return 0 end context_name = config.add_context(name: name, repo_path: repo_path, branch: branch) out.puts("Created context #{context_name} -> #{File.(repo_path)} @ #{branch}") 0 rescue OptionParser::InvalidOption => e err.puts("dx: #{e.}") usage_error("dx create [-c NAME] [-n] [-v] NAME [PATH] [BRANCH]") end |