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

Align installed command output into columns for interactive terminals #134

Merged

Conversation

interstateone
Copy link
Contributor

@interstateone interstateone commented Jan 29, 2021

The intent of #23 was to make it possible to get the path of installed Xcodes more easily, which was implemented by #133. I realized after I wrote the description of that issue that it should be possible to both make the output nice for humans and also make it easy to pipe to other commands to get the paths for scripting purposes. This PR makes that change.

If standard output is an interactive terminal, which is what you'll see most of the time as a user, space will be added between the two columns so that it's easy to read. If standard output is not an interactive terminal, like when you pipe the output to another command or a file, then no spaces will be added and the current behaviour of adding a tab character will be used.

The expected behaviour is below, which you can try out to verify.

When printing to an interactive terminal:

❯ swift run xcodes installed
10.1                           /Applications/Xcode-10.1.app
10.2.1                         /Applications/Xcode-10.2.1.app
11.0                           /Applications/Xcode-11.0.0.app
11.2                           /Applications/Xcode-11.2.0.app
11.2.1                         /Applications/Xcode-11.2.1.app
11.3                           /Applications/Xcode-11.3.0.app
11.4                           /Applications/Xcode-11.4.0.app
11.4.1                         /Applications/Xcode-11.4.1.app
11.5                           /Applications/Xcode-11.5.0.app
11.6                           /Applications/Xcode-11.6.0.app
11.7                           /Applications/Xcode-11.7.0.app
12.0.1                         /Applications/Xcode-12.0.1.app
12.2 Beta (12B5018i)           /Applications/Xcode-12.2.0-Beta.app
12.2                           /Applications/Xcode-12.2.0.app
12.3 Beta (12C5020f)           /Applications/Xcode-12.3.0-Beta.app
12.3 (Selected)                /Applications/Xcode-12.3.0.app
12.4 Release Candidate (12D4e) /Applications/Xcode-12.4.0-Release.Candidate.app

When not printing to an interactive terminal:

❯ swift run xcodes installed > test; cat test
10.1	/Applications/Xcode-10.1.app
10.2.1	/Applications/Xcode-10.2.1.app
11.0	/Applications/Xcode-11.0.0.app
11.2	/Applications/Xcode-11.2.0.app
11.2.1	/Applications/Xcode-11.2.1.app
11.3	/Applications/Xcode-11.3.0.app
11.4	/Applications/Xcode-11.4.0.app
11.4.1	/Applications/Xcode-11.4.1.app
11.5	/Applications/Xcode-11.5.0.app
11.6	/Applications/Xcode-11.6.0.app
11.7	/Applications/Xcode-11.7.0.app
12.0.1	/Applications/Xcode-12.0.1.app
12.2 Beta (12B5018i)	/Applications/Xcode-12.2.0-Beta.app
12.2	/Applications/Xcode-12.2.0.app
12.3 Beta (12C5020f)	/Applications/Xcode-12.3.0-Beta.app
12.3 (Selected)	/Applications/Xcode-12.3.0.app
12.4 Release Candidate (12D4e)	/Applications/Xcode-12.4.0-Release.Candidate.app

@interstateone interstateone requested a review from a team January 29, 2021 00:06
@interstateone interstateone merged commit 115de35 into XcodesOrg:main Feb 2, 2021
@interstateone interstateone deleted the format-installed-columns branch February 2, 2021 03:43
@interstateone interstateone added the enhancement New feature or request label Feb 2, 2021
interstateone added a commit that referenced this pull request Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants