Replies: 1 comment
-
Thx Stuart for writing it down! I apologize this post is using English and not shell code examples but I am in a bit of a hurry and playing catch up from the long weekend. Back compatUser experienceHow We can allow the user to force a default behavior with an environment variable, possibly combined with the presence of the config file to control the
ImplementationI like the idea of keeping the legacy interface completely separate from the modern CLI implementation. No inheritance of commands, no inheritance of flags from the root, etc. We can replace Kong with a vanilla Cobra implementation in Open issues
Global flags and subcommandsThis section leaves the legacy behaviours behind and focuses on the modern experience. User experienceWe prefer users rely on the stored configuration for the bulk of connection parameters. There are certain connection string parameters that are not desirable to expose as overrides, particularly The legacy Furthermore, modern I propose we eliminate the old flag-per-setting model and move to a generic name-value dictionary for connection overrides as a global parameter. It could be similar to how Potential global flags:
Note that we can still allow SQL-specific commands like Open issues
|
Beta Was this translation helpful? Give feedback.
-
The purpose of this discussions is to come up with a plan on how to implement #180, which is the first of what will be several PRs, that wire up the old ODBC sqlcmd flags to the new cobra based modern sub-command approach to the sqlcmd CLI, while still maintaining backward compatibility with the command-line.
With the new sub-command based cobra based CLI, e.g:
And the new "install" (create is synonym) sub-command, so end users can get going with a T/SQL endpoint directly from sqlcmd, which also populates a ~/sqlcmd/sqlconfig file which provides a current context, which provides default parameters for hostname/port/credentials etc. (which otherwise would have been provided by parameters like -S, -U, -P etc.).
We have also implemented all the back-compat flags from the old ODBC based sqlcmd, which does not use sub-commands at all, and instead only uses command line flags (no sub-commands), so if a user provides a sqlcmd command-line with no sub-commands (and only flags), we run in back-compat mode.
A user may run in back-compat mode (no sub-command), but may have a current context (from sqlconfig), which can populate values like -S, -U etc.
Also a user may have a current-context, which would by default populate the equivalent of -S, -U etc., but the user may also provide the -S, -U parameters with the intention of override the values in the sqlconfig (current context).
Cobra also has the concept of global flags, what flags should we make global. Does a global flag have to apply all sub-commands, e.g. -U (username) or -E (trusted) doesn't apply to
sqlcmd install
, but does apply tosqlcmd query
andsqlcmd bulk
Some Options (non-exhaustive):
What should --help display and when:
Another angle to consider is the command line help to display. Currently the kong based go-sqlcmd implementation produces several console pages of help with the standard sqlcmd -?.
A modern cobra CLI would usually produce a single level description for the top level subcommands and describe only the global flags with a --help (with no other args provided). Also, a modern cobra CLI would normally produce the same help if no sub-command is entered, however, the older ODBC based sqlcmd.exe makes a Trusted connection (-E) to the localhost (-S .) if no command line options are provided, we need to solve for these two approaches to providing no command options/sub-commands.
We could consider a different behavior if a environment variable is present e.g. if SQLCMD_BACKCOMPAT_MODE=TRUE we could behave in an old way, and behave in the standard modern way if env var is not present
The purpose of this discussion is to write down a plan on how we are going to make this all work together and implement it in a consistent manner.
Beta Was this translation helpful? Give feedback.
All reactions