Skip to content

Commit

Permalink
update_usage script to update usage in README
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Mar 24, 2020
1 parent a41b73f commit 08ad629
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ bindir = $(prefix)/bin
INSTALL = install
INSTALL_PROGRAM = $(INSTALL) -m 755

build: blueutil
build: blueutil update_usage

format:
clang-format -i *.m

update_usage: blueutil
./update_usage
touch update_usage

test: build
./test

Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CLI for bluetooth on OSX: power, discoverable state, list, inquire devices, conn

## Usage

<!--USAGE[-->
```
Usage:
blueutil [options]
Expand All @@ -18,27 +19,40 @@ Without options outputs current state
--favourites list favourite devices
--inquiry [T] inquiry devices in range, 10 seconds duration by default excluding time for name updates
--paired list paired devices
--recent [N] list recently used devices, 10 by default
--recent [N] list recently used devices, 10 by default, 0 to list all
--info ID show information about device
--is-connected ID connected state of device as 1 or 0
--connect ID create a connection to device
--disconnect ID close the connection to device
--pair ID [PIN] pair with device, optional PIN of up to 16 characters will be used instead of interactive input if requested in specific pair mode
--add-favourite ID add to favourites
--remove-favourite ID remove from favourites
--format FORMAT change output format of info and all listing commands
--wait-connect ID [TIMEOUT]
EXPERIMENTAL wait for device to connect
--wait-disconnect ID [TIMEOUT]
EXPERIMENTAL wait for device to disconnect
--wait-rssi ID OP VALUE [PERIOD [TIMEOUT]]
EXPERIMENTAL wait for device RSSI value which is 0 for golden range, -129 if it cannot be read (e.g. device is disconnected)
-h, --help this help
-v, --version show version
STATE can be one of: 1, on, 0, off, toggle
ID can be either address in form xxxxxxxxxxxx, xx-xx-xx-xx-xx-xx or xx:xx:xx:xx:xx:xx, or name of device to search in used devices
OP can be one of: >, >=, <, <=, =, !=; or equivalents: gt, ge, lt, le, eq, ne
PERIOD is in seconds, defaults to 1
TIMEOUT is in seconds, default value 0 doesn't add timeout
FORMAT can be one of:
default - human readable text output not intended for consumption by scripts
new-default - human readable comma separated key-value pairs (EXPERIMENTAL, THE BEHAVIOUR MAY CHANGE)
json - compact JSON
json-pretty - pretty printed JSON
```
<!--]USAGE-->

## Install/update/uninstall

Expand Down
21 changes: 21 additions & 0 deletions update_usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env ruby

require 'pathname'

USAGE_REGEXP = /
(?<open>#{Regexp.escape '<!--USAGE[-->'})
.*
(?<close>#{Regexp.escape '<!--]USAGE-->'})
/mx

path = Pathname('README.md')

original = path.read
changed = original.sub(USAGE_REGEXP) do
m = Regexp.last_match
system 'make -s blueutil'
usage = `./blueutil --help`.sub(/\Ablueutil v.*/, '').lstrip
"#{m[:open]}\n```\n#{usage}```\n#{m[:close]}"
end

path.open('w'){ |f| f.write(changed) } unless original == changed

0 comments on commit 08ad629

Please sign in to comment.