Skip to content

Commit 27d4097

Browse files
authored
Merge pull request gpiozero#604 from RPi-Distro/pinout-xyz
Add --xyz option to pinout cli tool
2 parents 7255802 + fba1829 commit 27d4097

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

docs/cli_pinout.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Synopsis
88

99
::
1010

11-
pinout [-h] [-r REVISION] [-c] [-m]
11+
pinout [-h] [-r REVISION] [-c] [-m] [-x]
1212

1313
Description
1414
-----------
@@ -41,6 +41,10 @@ Options
4141

4242
Force monochrome output. See also :option:`--color`
4343

44+
.. option:: -x, --xyz
45+
46+
Open `pinout.xyz`_ in the default web browser
47+
4448
Examples
4549
--------
4650

@@ -172,4 +176,5 @@ PIGPIO_PORT
172176

173177
:manpage:`remote-gpio(7)`
174178

175-
.. _revision codes: http://elinux.org/RPi_HardwareHistory
179+
.. _pinout.xyz: https://pinout.xyz/
180+
.. _revision codes: https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md

gpiozerocli/pinout.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import sys
1414
import textwrap
1515
import warnings
16+
import webbrowser
1617

1718
class PinoutTool(object):
1819
def __init__(self):
@@ -38,6 +39,12 @@ def __init__(self):
3839
action='store_false',
3940
help='Force monochrome output. See also --color'
4041
)
42+
self.parser.add_argument(
43+
'-x', '--xyz',
44+
dest='xyz',
45+
action='store_true',
46+
help='Open pinout.xyz in the default web browser'
47+
)
4148

4249
def __call__(self, args=None):
4350
if args is None:
@@ -69,23 +76,27 @@ def main(self, args):
6976
"remotely access your Pi."
7077
)
7178
formatter.add_text(
72-
"* https://gpiozero.readthedocs.io/en/latest/remote_gpio.html"
79+
"* https://gpiozero.readthedocs.io/en/stable/remote_gpio.html"
7380
)
7481
sys.stderr.write(formatter.format_help())
7582
else:
76-
if args.revision == '':
77-
try:
78-
pi_info().pprint(color=args.color)
79-
except IOError:
80-
raise IOError('This device is not a Raspberry Pi')
83+
if args.xyz:
84+
webbrowser.open('https://pinout.xyz')
8185
else:
82-
pi_info(args.revision).pprint(color=args.color)
83-
formatter = self.parser._get_formatter()
84-
formatter.add_text(
85-
"For further information, please refer to https://pinout.xyz/"
86-
)
87-
sys.stdout.write('\n')
88-
sys.stdout.write(formatter.format_help())
86+
if args.revision == '':
87+
try:
88+
pi_info().pprint(color=args.color)
89+
except IOError:
90+
raise IOError('This device is not a Raspberry Pi')
91+
else:
92+
pi_info(args.revision).pprint(color=args.color)
93+
formatter = self.parser._get_formatter()
94+
formatter.add_text(
95+
"For further information, please refer to "
96+
"https://pinout.xyz/"
97+
)
98+
sys.stdout.write('\n')
99+
sys.stdout.write(formatter.format_help())
89100

90101

91102
main = PinoutTool()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy