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

Added hs config commands #464

Merged
merged 34 commits into from
May 26, 2021
Merged

Added hs config commands #464

merged 34 commits into from
May 26, 2021

Conversation

miketalley
Copy link
Contributor

@miketalley miketalley commented Apr 5, 2021

Description and Context

#27 Finally getting around to this

Adds six new commands

  • hs config set default-account [accountNameOrId] - selects portal to use as defaultPortal from a list or by specifying accountNameOrId
  • hs config set default-mode [mode] - selects mode to use as defaultMode in config, also supports specifying mode as argument
  • hs config set http-timeout <timeout> - sets httpTimeout in config
  • hs config set allow-usage-tracking - selects value for allowUsageTracking in config
  • hs accounts list (alias hs accounts ls) - lists portal names, portalIds, and authTypes in table format as well as defaultPortal
  • hs accounts rename <currentNameOrId> <newName> - allows naming/renaming a portal name in the config (will also update defaultPortal if that is the one that is renamed)

Screenshots

hs config set default-account
image

hs config set default-mode
image

hs config set http-timeout
image

hs config set allow-usage-tracking
image

hs accounts list
image

hs accounts rename
image

Notes:

@miketalley miketalley marked this pull request as ready for review April 5, 2021 22:21
@miketalley
Copy link
Contributor Author

miketalley commented Apr 6, 2021

@abelb @jasminetudor do you have any suggestions on this?

Copy link
Contributor

@gcorne gcorne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a UX perspective, I wonder if we should assume that the only actions that can be taken are to interact with the accounts in the config. I say this because there are other global config options that could have corresponding config commands for updating them, which makes me wonder if we should have commands like hs config rename-account and hs config default-account or similar.

I also didn't comment on all the places where portal is used instead of account in user-facing copy.

packages/cli-lib/lib/config.js Show resolved Hide resolved
packages/cli/commands/config.js Outdated Show resolved Hide resolved
packages/cli/commands/config/default.js Outdated Show resolved Hide resolved
packages/cli/commands/config/default.js Outdated Show resolved Hide resolved
packages/cli/commands/config/default.js Outdated Show resolved Hide resolved
packages/cli/commands/config/list.js Outdated Show resolved Hide resolved
packages/cli/commands/config/list.js Outdated Show resolved Hide resolved
packages/cli/commands/config/list.js Outdated Show resolved Hide resolved
packages/cli/commands/config/list.js Outdated Show resolved Hide resolved
packages/cli-lib/lib/config.js Show resolved Hide resolved

const config = getConfig();
const portalData = config.portals.reduce((acc, portal) => {
acc.push([portal.name, portal.portalId, portal.authType]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if authType should be an enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could definitely make it an enum though it's not elsewhere in the code. I think doing this may be out of scope for this PR though.

Is there something that you're worried about with not using an enum here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry I was thinking that we could validate that a correct authType exists but might not be a big deal

.command({
...list,
aliases: 'ls',
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding the alias here, can we add to the command in config/list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we list aliases of subcommands in the parent command we don't have to sift through each subcommand to find every alias and avoid collisions. It also matches the current pattern for the hs list (hs ls) and hs functions list (hs functions ls).

@brandenrodgers
Copy link
Contributor

When running hs config default, should we have special handling if there is only one available account to choose from?
image
In this scenario I only have one account so maybe it could instead show something like "You only have one account configured. Add more accounts to your hubspot.config.yml to see more options here". My phrasing there probably isn't the best, but I'm trying to think of ways to help guide the user to their intended result.

@brandenrodgers
Copy link
Contributor

I'm seeing an issue in the hs config rename command where it's not correctly logging the original account name:
image

portalData.unshift(getTableHeader(['Name', 'Portal ID', 'Auth Type']));

logger.log(getTableContents(portalData));
logger.log('Default Portal: ', config.defaultPortal);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the best place for this, but it would be helpful to print out the path of the config file, which might be helpful for folks to know which config the CLI is actually loading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I updated the output from this command to include the config path and made the accounts list a bit nicer too
image

@erincouse
Copy link

@gcorne can you give me an example of the global config commands that would conflict with these?

@gcorne
Copy link
Contributor

gcorne commented Apr 23, 2021

@gcorne can you give me an example of the global config commands that would conflict with these?

Since hs config is being introduced here, there isn't a conflict. It is more of a design issue in that the structure of the commands don't match the structure of the configuration. The configuration consists of two sections: 1) global config options and 2) config for each account that the CLI has been set up to access.

Global configuration options:

  1. httpTimeout - controls how long the CLI waits for network requests to the backend to complete. This is an advanced feature.
  2. allowUserTracking - controls whether or not CLI usage activity is being tracked
  3. defaultPortal - default account used when running commands without passing --acount option
  4. defaultMode - determines whether files will automatically be overwritten or not when running hs fetch

Account configuration:

  1. Name
  2. Authentication type

@jasminetudor
Copy link

jasminetudor commented Apr 23, 2021

@miketalley we are thinking...
Great:
hs config list
hs config rename

but we would change:

hs config rename <currentNameOrId> <newName>
to
hs config set --default= <accountId>

to stick with the format of:

hs 
	command	noun (feature you need to use) 
	subcommand	verb (what you want to do w it)
	flags 	parameter (limits or specifics)

@miketalley
Copy link
Contributor Author

@miketalley we are thinking...
Great:
hs config list
hs config rename

but we would change:

hs config rename <currentNameOrId> <newName>
to
hs config set --default= <accountId>

to stick with the format of:

hs 
	command	noun (feature you need to use) 
	subcommand	verb (what you want to do w it)
	flags 	parameter (limits or specifics)

To clarify -- hs config list and hs config rename should remain as-is in the current PR and hs config default should be renamed to hs config set with 0 positional arguments and 1 option (default) that can be used to specify the new defaultName value?

For example:
hs config set --default=accountNameToSetAsDefault -- updates defaultPortal in config to accountNameToSetAsDefault
hs config set -- display error? display help? -- this is the part that seems a bit strange (see below)

Having 0 positional arguments for a command is a bit strange to me. I don't think that there are currently any other commands in the CLI that do not function unless an --option is passed. If hs config default were to be renamed to hs config set default <newDefaultValue> that would fit the current command paradigm better I think.

What are other people's thoughts?

@miketalley
Copy link
Contributor Author

miketalley commented Apr 26, 2021

After discussion with @erincouse and @jasminetudor on the hs config default command we decided to use hs config set default [newDefaultAccountNameOrId].

It can be used to select from a list by running hs config set default or a name or portalId value can be specified as a positional argument -- hs config set default MyAccountName / hs config set default 1234567.

@miketalley miketalley requested a review from gcorne April 27, 2021 13:54
@gcorne
Copy link
Contributor

gcorne commented Apr 28, 2021

Maybe it is just me, but I struggle with the expectations when it comes to hs config list. I expect it to list the current config values not just the list of accounts. I also feel like "default" needs a qualifier because the config also stores other defaults like the default mode used when running hs fetch.

@miketalley
Copy link
Contributor Author

miketalley commented Apr 28, 2021

Maybe it is just me, but I struggle with the expectations when it comes to hs config list. I expect it to list the current config values not just the list of accounts. I also feel like "default" needs a qualifier because the config also stores other defaults like the default mode used when running hs fetch.

We can definitely expand the output to include defaultMode, httpTimeout and allowUsageTracking (not sure if I missed any others). Are you thinking we should also make the output friendly to pipe to other commands? I'm interested to know which use cases you'd like to cover. I'm not sure that outputting the tokens/access keys would be a good idea.

I think changing the hs config set default command to hs config set default-account would be a good idea to avoid ambiguity. Adding hs config set default-mode, hs config set http-timeout, and hs config set allow-usage-tracking would also be good to completely flesh out the hs config set subcommands.

@gcorne
Copy link
Contributor

gcorne commented Apr 28, 2021

I think I am stuck on hs config list and hs config rename being operations on accounts in a config not the config itself. It makes me wonder if hs accounts might be a clearer top-level command for the account operations.

@miketalley
Copy link
Contributor Author

I think I am stuck on hs config list and hs config rename being operations on accounts in a config not the config itself. It makes me wonder if hs accounts might be a clearer top-level command for the account operations.

I'd be fine with having this functionality nested as hs accounts instead. How do you see hs config working, then?

@gcorne
Copy link
Contributor

gcorne commented May 4, 2021

How do you see hs config working, then?

I'd imagine that it would be used for the "global" config options that are not related to a specific account like defaultMode.

@erincouse
Copy link

Small comment: I think hs accounts rename makes more sense as hs config rename (but understand that that may add complexity down the line, so not super hung up on it). Other is a general content nit: There's a lot of interchangeable use of portal and account, and it should really always be account as much as possible. It causes a lot of internal and external confusion because we aren't consistent with our own language.

@abelb
Copy link

abelb commented May 13, 2021

One idea is to maybe do this?
hs config accounts rename <currentNameOrId> <newName>
hs config accounts list

It makes the commands longer but it nests them underneath config and renaming them AND the list are all data that lives in config.

Thoughts @jasminetudor @erincouse @miketalley?

Small comment: I think hs accounts rename makes more sense as hs config rename (but understand that that may add complexity down the line, so not super hung up on it).

@abelb
Copy link

abelb commented May 13, 2021

Otherwise @miketalley everything looks good to me!

@gcorne
Copy link
Contributor

gcorne commented May 14, 2021

Small comment: I think hs accounts rename makes more sense as hs config rename (but understand that that may add complexity down the line, so not super hung up on it).

@erincouse can you elaborate on why? Is your expectation that hs accounts rename would make changes to the name of the account inside HubSpot instead of the name that the developer chose when setting it up using hs init or hs auth? I think from an ergonomics perspective that hs accounts rename makes sense to me because all the other commands use the name as the value for --account. I also think we should consider deprecating hs auth in favor of hs accounts add since I think that is clearer. It will also make documenting how a developer can juggle multiple accounts (such as DEV, QA, PROD) via the CLI more straightforward.

@gcorne
Copy link
Contributor

gcorne commented May 14, 2021

In addition to hs accounts add, I could see hs accounts set-default and hs accounts remove being valuable to round things out.

@miketalley
Copy link
Contributor Author

I think there are two ways to organize the commands that are being thought about...

  1. Commands that modify the hubspot.config.yml file are nested as hs config <command>
  2. Commands that modify root level config values within hubspot.config.yml are hs config <command> and commands that modify the portals array values are hs accounts <command>

I can see good reasons for each. Having the rename command as hs accounts rename makes more sense to me because it doesn't leave any question about what is being renamed. It also leaves us the open possibility of having other rename commands to rename something else in the config in the future and nesting those separately. I can't think of a drawback to having multiple commands that can make changes to the config file values. 🤔

That said, I think @gcorne's idea (and as @erincouse, @abelb, @jasminetudor, and I have discussed separately) of deprecating hs auth in favor of hs accounts add. I think that work should be done in a separate PR -- as well as potentially adding hs accounts remove.

@miketalley miketalley merged commit 146d82d into master May 26, 2021
@miketalley miketalley deleted the issues/27-hs-config branch May 26, 2021 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants