Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

Refactor to enable packaging glab inside another golang CLI tool (overriding config location) #843

Closed
addshore opened this issue Sep 21, 2021 · 4 comments · Fixed by #845
Labels
enhancement New feature or request

Comments

@addshore
Copy link
Contributor

Describe the feature or problem you'd like to solve

I would like to incorporate a gitlab sub command into a CLI I am developing for MediaWiki / Wikimedia developers.
This would work as part of an already released binary, and be automatically configured to point to the Wikimedia Gitlab instance

Propose a Solution

Refactor glinstance and or Factory to allow overriding the location of the configuration file as well as the domain to be use for gitlab.
This would allow users to use a version of the glab CLI packaged within the mwcli as well as a standalone glab binary pointing to the default instance.

Additional context

It would appear something like this:

image

Other CLI codebase: https://gitlab.wikimedia.org/releng/cli

@addshore addshore added the enhancement New feature or request label Sep 21, 2021
@profclems
Copy link
Owner

Hi @addshore, I didn't really expect a use case like this for glab. With this, you need access to the internal packages like glinstance and config.

For instance, to override the default host, you need to use the glinstance.OverrideDefaultProtocol(host) which is in the internal/glinstance package.

func OverrideDefault(newhost string) {
hostnameOverride = newhost
}

I can confirm that it's safe to move these packages to the pkg folder but I don't know if I will be able to work on this anytime soon. This is open in case you'd like to take this up.

@addshore
Copy link
Contributor Author

Great!
I'll try and have a go moving these things around!

@addshore
Copy link
Contributor Author

Ahh right there is per host config already it seems?

./bin/mw glab config get -g
Error: accepts 1 arg(s), received 0
Usage:  mw glab config get <key> [flags]

Flags:
  -g, --global        Read from global config file (~/.config/glab-cli/config.yml). [Default: looks through Environment variables → Local → Global]
  -h, --host string   Get per-host setting

accepts 1 arg(s), received 0

So I could leave the configuration location etc totally untouched? just changing the default host probably?

@profclems
Copy link
Owner

Yeah you only need to change the default host and leave the config untouched.
glab already supports per-host config

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants