-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back the YAML pasting dialog for stack commands (#46)
- Loading branch information
Showing
4 changed files
with
59 additions
and
32 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'kontena/cli/stacks/yaml/stack_file_loader' | ||
|
||
module Kontena | ||
module Plugin | ||
module Shell | ||
class PromptLoader < Kontena::Cli::Stacks::YAML::StackFileLoader | ||
def self.match?(source, parent = nil) | ||
source.end_with?('kontena.yml') && !Kontena::Cli::Stacks::YAML::FileLoader.match?(source, parent) | ||
end | ||
|
||
def read_content | ||
content = Kontena.prompt.multiline("Enter or paste a stack YAML").join | ||
raise "Invalid stack YAML" unless YAML.safe_load(content).kind_of?(Hash) | ||
content | ||
end | ||
|
||
def origin | ||
"prompt" | ||
end | ||
|
||
def registry | ||
"prompt" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'tempfile' | ||
|
||
module Kontena | ||
module Plugin | ||
module Shell | ||
module StacksCommonExt | ||
def reader_from_yaml(*args) | ||
if args.first == 'kontena.yml' && !File.exist?('kontena.yml') | ||
tempfile = Tempfile.new('kontena.yml') | ||
tempfile.write(Kontena.prompt.multiline("Enter or paste a stack YAML").join) | ||
tempfile.close | ||
args[0] = tempfile.path | ||
end | ||
reader = super(*args) | ||
File.unlink(args[0]) if File.exist?(args[0]) | ||
reader | ||
end | ||
end | ||
end | ||
end | ||
end |