-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tink template create
now accepts data from STDIN
#133
Conversation
cmd/tink-cli/cmd/template/create.go
Outdated
@@ -36,40 +57,55 @@ func addFlags() { | |||
flags.StringVarP(&filePath, "path", "p", "", "path to the template file") | |||
flags.StringVarP(&templateName, "name", "n", "", "unique name for the template (alphanumeric)") | |||
|
|||
createCmd.MarkPersistentFlagRequired(fPath) | |||
// createCmd.MarkPersistentFlagRequired(fPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just remove this commented line as its not used anymore.
You should remove this from the example that is on this PR description as there is no need to specify the path when it reads from stdin. |
I would prefer to keep it to make sure that people know about this. |
If you want to be able to use This because I'm not sure if all unices have a |
cmd/tink-cli/cmd/template/create.go
Outdated
} | ||
return data | ||
} | ||
|
||
func createTemplate(c *cobra.Command, args []string) { | ||
req := template.WorkflowTemplate{Name: templateName, Data: readTemplateData()} | ||
func createTemplate(c *cobra.Command, data []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're at it, I think we should reduce the globals used in this function and pass templateName
as a parameter to the function to reduce spooky action. Could we do the same for filePath
in readTemplateData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFIK, since templateName
and filePath
are value receivers for the flags, they have to be global. But if there is a better way to do that, please do let me know.
cmd/tink-cli/cmd/template/create.go
Outdated
if isInputFromPipe() { | ||
data = readDataFromStdin() | ||
} else { | ||
data = readTemplateData() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we reversed this logic a bit, and instead got an io reader:
path, _: c.Flags().GetString(fPath)
if path != "" {
reader, err = os.Open(filePath)
...
} else {
reader = os.Stdin
}
and then just readAll(reader)
? As it stands, it will fairly eagerly read the input from stdin even if I've passed a file.
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
Signed-off-by: Gaurav Gahlot <[email protected]>
It looks good to me I don't have anything to add other what got already adressed |
At present, we create a template as shown below:
With the code changes in place, a user can now pipe the template data from a file. For example, if the data is saved in
/tmp/example.tmpl
, you can create a template with either of the following:Signed-off-by: Gaurav Gahlot [email protected]