Commit graph

99 commits

Author SHA1 Message Date
Alan Donovan
f4491c7a80 Add FlagErrorf; encapsulate FlagError.error 2021-10-21 11:40:20 -04:00
Mislav Marohnić
2ca18e0600 Warn about missing OAuth scopes when reporting HTTP 4xx errors
If a 4xx server response lists scopes in the X-Accepted-Oauth-Scopes
header that are not present in the X-Oauth-Scopes header, the final
error messaging on stderr will now include a hint for the user that they
might need to request the additional scope:

    $ gh codespace list
    error getting codespaces: HTTP 403: Must have admin rights to Repository. (https://api.github.com/user/codespaces?per_page=30)
    This API operation needs the "codespace" scope. To request it, run:  gh auth refresh -h github.com -s codespace
2021-10-13 23:24:14 +02:00
Mislav Marohnić
d853ce5bc9 Avoid resolving executable() until requested at runtime
This is to avoid hitting the filesystem and resolving symlinks
unnecessarily. The value of executable is just used conditionally by a
handful of commands.
2021-09-24 14:42:41 +02:00
Mislav Marohnić
8f3b6749d7
Merge pull request #4241 from cli/saml-error
Suggest to re-authenticate to fix "SAML enforcement" error
2021-09-03 16:10:16 +02:00
Mislav Marohnić
b0b67014f1 Suggest to re-authenticate to fix "SAML enforcement" error
As far as I can put together, this error appears when someone has
authenticated GitHub CLI with a PAT that isn't authorized to access a
certain org. It can also happen if someone has authorized GitHub CLI
using the legacy "GitHub CLI (dev)" OAuth app instead of our production
OAuth app.

Doing `gh auth refresh` will re-authenticate the user using our
production "GitHub CLI" OAuth app which will not have problems accessing
resources in different GitHub organizations.
2021-08-30 17:18:59 +02:00
Mislav Marohnić
11fbb60ae7 Rename the module to "github.com/cli/cli/v2" 2021-08-25 12:41:30 +02:00
Mislav Marohnić
af2aecd40b
Merge pull request #4146 from cli/force-tty
Add ability to force terminal-style output even when redirected
2021-08-23 16:46:14 +02:00
Mislav Marohnić
8129fb3d3e
Merge pull request #4171 from mahdyar/chore/make-gh-status-clickable
chore: make gh status link clickable
2021-08-23 13:12:35 +02:00
Mahdyar Hasanpour
db74830e64
chore: make gh status clickable
Adding https:// to githubstatus.com to make it clickable on terminal emulators
2021-08-22 18:01:55 +04:30
Mislav Marohnić
51d609078b Enable gh help <command> for extensions
This sends the `--help` flag to the extension. The extension is
reponsible for printing something useful as a result.
2021-08-19 20:38:19 +02:00
Mislav Marohnić
321fd98f82 Add ability to force terminal-style output even when redirected 2021-08-17 20:12:25 +02:00
Mislav Marohnić
0d999ddaa1 Rework local extensions for Windows
Replace the implementation that relied on symlinks with the one that
create regular files that act like symlinks: they contain a reference to
the local directory where to find the extension.
2021-07-28 22:47:54 +02:00
Sam
33c3fb5cdd
Merge pull request #3870 from cli/extensions-revisited
Improvements to gh extensions
2021-06-28 17:12:29 -07:00
Mislav Marohnić
1ec47d8191 Improvements to gh extensions
- Extensions on Windows now enabled through the `sh.exe` interpreter
- `sh.exe` now found on Windows when git was installed via scoop
- `gh extensions list` command shows origin repo for the extension
- `gh extensions upgrade --all` is required to upgrade all extensions
- Added `gh extensions remove`
- Shell completions now include aliases and extension names
- `gh` help output now lists available extension names
- Extensions are stored to XDG_DATA_HOME
2021-06-21 16:54:08 +02:00
Mislav Marohnić
8ff42bf28c Fix repo override 2021-06-17 17:58:46 +02:00
Mislav Marohnić
8dd1e12f64 Merge remote-tracking branch 'origin' into fix-actions-help 2021-06-17 16:13:34 +02:00
Mislav Marohnić
883943946a Add a global pre-run hook to handle auth check and repo override
With auth check being done via Cobra hooks, it is automatically skipped
for non-runnable commands and `-h/--help` flag usage.
2021-06-17 16:01:57 +02:00
chemotaxis
1e3bba5ff6 Add comment about cmd.Help()
The linter picked up that the error value from cmd.Help() isn't checked.

Even though cmd.Help() returns an error value, it's always nil. The
inner HelpFunc() function directly prints the error message instead of
returning an error value.
2021-06-16 22:28:41 -04:00
chemotaxis
558ff2dff0 Skip authentication message if asking for help
Currently, this still checks authentication, but we skip the
authentication message and exit normally.
2021-06-16 14:25:08 -04:00
chemotaxis
c903f1ecd0 Ask for and print help even if logged out
You have to explicitly ask for help using the help flags.  Otherwise,
`gh` will just print the authentication message.
2021-06-16 01:18:52 -04:00
Sam Coe
edfac42384
Set up iostreams in factory default 2021-06-15 09:20:00 -04:00
Cristian Dominguez
b3c2318e09 Increase GH_PAGER precedence
If `GH_PAGER` is exists, set it as the pager even if one is
already set in config.

This allows a user to change/disable the pager per single invocation.
2021-06-04 23:22:37 -03:00
Mislav Marohnić
ffebd23ba7
Merge pull request #3761 from cli/command-extensions
Experimental command extensions support
2021-06-03 19:13:38 +02:00
Mislav Marohnić
fce93d6080 Experimental command extensions support
Extensions are looked up as `~/.config/gh/extensions/gh-*`.
Additionally, any executables found in PATH named `gh-*` are available
as `gh <command>`.
2021-06-01 17:15:20 +02:00
Sam Coe
583e74d70c
Add support for XDG_STATE_HOME 2021-05-25 16:30:51 -04:00
nate smith
9f451d9eef review feedback 2021-04-29 16:06:26 -05:00
nate smith
02e9fa086d start on incorrect function error handling 2021-04-28 13:59:54 -05:00
Junjie Yuan
927e4c7e4d
using filepath.Join() instead of path.Join() to fix wrong filepath on Windows:
PS C:\Users\Junjie Yuan> gh auth status
github.com
  ✓ Logged in to github.com as junjieyuan (C:\Users\Junjie Yuan\.config\gh/hosts.yml)
  ✓ Git operations for github.com configured to use https protocol.
  ✓ Token: *******************

Signed-off-by: Junjie Yuan <yuan@junjie.pro>
2021-04-22 15:19:16 +08:00
Mislav Marohnić
69ca2dda4a Quick fix: respect default hostname when parsing owner/repo pairs
This re-enables using GH_HOST to set a default hostname when
supplying repo argument like `gh repo clone owner/repo`.
2021-04-02 15:16:27 +02:00
Sam
9ec1e21d4c
Default to GHES host if only GHES is authenticated (#3286) 2021-03-30 16:51:00 +02:00
Mislav Marohnić
c63247f0ea Avoid checking for new releases when authenticating git
Avoid displaying upgrade notice if any output is redirected. This also
alleviates the need to specifically check for `gh completion -s
<shell>`, `gh __complete`, and other scripting scenarios where we
absolutely don't want to trigger any upgrade checks or notices.
2021-03-04 17:39:25 +01:00
Mislav Marohnić
aa5cf6c48a
Merge pull request #3075 from cli/credential-helper-absolute
Use absolute path when configuring gh as git credential
2021-03-04 13:51:24 +01:00
Mislav Marohnić
cfbfb578f0 Read Executable from factory instead of from stdlib 2021-03-04 13:41:50 +01:00
Mislav Marohnić
9234163679 Formalize gh process exit codes
Here are the statuses:
- 0: success
- 1: misc. error
- 2: user interrupt/cancellation
- 4: authentication needed

These old exit codes are now changed to "1":
- we used to return "2" for config file errors;
- we used to return "2" for alias expansion errors;
- we used to return "3" for alias runtime errors.

I do not believe that there is a need to distinguish these specific
cases via exit status, and converting them to "1" frees codes "2" and
"3" for more practical use.
2021-03-04 13:35:59 +01:00
Mislav Marohnić
dd34cae112 Merge remote-tracking branch 'origin' into cancel-error-status 2021-03-02 13:52:07 +01:00
Mislav Marohnić
2ebdde1ddd Exit with status code "2" on user cancellation errors
This also stops printing "interrupt" after Ctrl-C is pressed.
2021-03-02 13:48:44 +01:00
Mislav Marohnić
27aea42d8a Avoid upgrade notice for recent release if gh is under Homebrew prefix
Before, when gh detected there was a new release in the `cli/cli` repo,
it would show this notice:

    A new release of gh is available: {V1} → {V2}

Additionally, when the release was more than 24h old, we would show this
to Homebrew users:

    To upgrade, run: brew update && brew upgrade gh

Ref. feb4acc2c0

This change makes it so that the original notice "A new release of gh is
available" is NOT shown to Homebrew users unless the release is older
than 24h. We effectively hide the fact that any release happened until
we're sure that the version bump has made it to `homebrew-core`.
2021-02-23 12:24:51 +01:00
Mislav Marohnić
feb4acc2c0 Suggest brew upgrade gh when new version detected
When the update notifier is enabled and a new version was detected, show
a Homebrew upgrade notice if:
- the release was at least 24 hours ago; and
- the current `gh` binary is under the Homebrew prefix.
2021-02-08 13:57:08 +01:00
Mislav Marohnić
2843ffff23 Classify the update package as internal 2020-12-15 16:09:08 +01:00
Nils Leif Fischer
413ccb71cc
Delete an error message that is not useful (and had a typo) 2020-11-30 13:20:43 +01:00
Sam Coe
2eb40f8a14
Empty auth token env variables are equal to being unset 2020-11-12 10:09:08 +03:00
Sam Coe
414de332fb
cleanup 2020-11-12 09:52:14 +03:00
Sam Coe
a79a0bbfd7
Add support for GH_TOKEN and GH_ENTERPRISE_TOKEN 2020-11-12 09:52:10 +03:00
Mislav Marohnić
5b4a08dcb9 Ensure that only PATH is searched when shelling out to external commands
Works around https://github.com/golang/go/issues/38736 for Windows.
2020-11-11 16:33:13 +01:00
Cristian Dominguez
79878a6736 Show MousetrapHelpText when double-clicking gh.exe 2020-11-09 08:28:55 -03:00
Nate Smith
24d863eccc
Merge pull request #2316 from cli/colors-1624
migrate off of utils color functions
2020-11-03 12:49:02 -06:00
Nate Smith
e7d934678d
Merge branch 'trunk' into run_from_explorer 2020-11-02 18:23:16 -06:00
vilmibm
f519989d5c move cobra mutation and document it 2020-11-02 16:22:02 -08:00
vilmibm
a2aa154794 port entirely to ColorScheme 2020-10-29 12:37:45 -07:00
Sam
edecb2e4f7
Merge pull request #2207 from cli/codespaces
[Codespaces] Support "integration" tokens
2020-10-27 15:37:02 +03:00