Skip to content
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

Persisting context for multiple projects #8

Closed
Souvikns opened this issue Jun 2, 2021 · 12 comments · Fixed by #14
Closed

Persisting context for multiple projects #8

Souvikns opened this issue Jun 2, 2021 · 12 comments · Fixed by #14
Labels

Comments

@Souvikns
Copy link
Member

Souvikns commented Jun 2, 2021

context should be optional, and I still should be able to pass context with a flag in case I'm doing some automation, or working with multiple files.

context should also be smart in the way that if I do not have context set, and I do not pass --context command, CLI check if there are files called asyncapi.json/yml/yaml in workdir, and picks them up.

context should most probably be persisted in a file.

I think we should store the context as a key:value pair of the directory the command was invoked to the context path

asyncapi context /path/to/spec/file

this command will save the {process.cwd(): "/path/to/spec/file"}, this way we can persist
the context for that specific folder/workspaces.

@Souvikns
Copy link
Member Author

I was thinking about the commands for setting the context and then also overriding it if the user wants. @derberg do let me know what you think about this -

To set, update and delete the context

asyncapi context --set <specPath | URL> set or update the context 
asyncapi context --remove clear the context 

To override the context or to use a temporary context we can have a --spec flag which would be a root level option.

asyncapi --spec=file/path/or/url generate <template>

@derberg
Copy link
Member

derberg commented Jun 16, 2021

I very much like kubectl and not having actions as flags, have a look at https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-context-and-configuration

asyncapi config get-contexts                          # display list of files in the context of the CLI
asyncapi config current-context                     # display the name of the file that is currently a context of the CLI
asyncapi config use-context myasyncapi

thoughts?

@Souvikns
Copy link
Member Author

Souvikns commented Jun 16, 2021

I very much like kubectl and not having actions as flags, have a look at https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-context-and-configuration

asyncapi config get-contexts                          # display list of files in the context of the CLI
asyncapi config current-context                     # display the name of the file that is currently a context of the CLI
asyncapi config use-context myasyncapi

thoughts?

Yeah, this is better, it's clear to understand.

So instead of flags, we use commands like

asyncapi context set <path|URL>
asyncapi context remove

So if context is a command then set and remove is an argument. Still, I guess we should have a flag if the user wants to override the context in any case.


One thing I would like to clarify, about saving the context. As we will be saving the <filePath | URL> of the spec file.
Most users will install CLI globally where they might have different projects that are using async API spec file for their development. If we have a single context then the user has to change/update the context every time he switches from one workspace to another. @derberg what do you think, we should do for this scenario.

  • One thing we can do is to let users save context in key-value pair where they can switch easily.
  • We save the context in a key-value pair from where the context set command was called. then the user doesn't have to update the context every time he opens a new folder.

@derberg
Copy link
Member

derberg commented Jun 16, 2021

except for setting and removing, user also needs a way to list all (to know which one to set) and to check what is the current.

the best would be to save the context file as .asyncapi in the "home" of the user, so where all files like .npm, .docker, .bash_profile and others. It is the best place because long term we need to make sure npm is not needed to install the CLI and should check out possibilities to publish it on managers like brew

@Souvikns
Copy link
Member Author

@derberg to sum up, how about these commands for the context.

asyncapi context set <context-name> <filePath | URL>   | set context 
asyncapi context current                               | get the current set context 
asyncapi context list                                  | list all the contexts 
asyncapi context remove                                | remove the current set context

@derberg
Copy link
Member

derberg commented Jun 17, 2021

if I want to switch from context A to B, would I use set? or we probably need use, right? this is how I have it in nvm, I do nvm use <node version> after listing what I have

@Souvikns
Copy link
Member Author

Yeah, use makes much more sense, but if use is changing the set context should we have another command for creating a new context value to be saved in the .asyncapi file, or use command will update/create a new context accordingly

@derberg
Copy link
Member

derberg commented Jun 17, 2021

use will be only for using existing one, set will be for setting a new one (and automatically set as current). Makes sense?

@Souvikns
Copy link
Member Author

use will be only for using existing one, set` will be for setting a new one (and automatically set as current). Makes sense?

ok, got it. 👍🏻

@Souvikns
Copy link
Member Author

@derberg shall I start working on this issue 😊.

@derberg
Copy link
Member

derberg commented Jun 18, 2021

@Souvikns I think it is about time. Just consider as small PRs as possible to make review and merge process easy, so not all commands at start.

also current --context flag will need to be fixed as now it points to a file and not context name, we just need another --file flag

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 0.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants