This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Delete cmd/airmatters * Get rid of main.go -> cmd/klimat/main.go * Implement publishing and discovery as subcommands
- Loading branch information
Showing
6 changed files
with
163 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/signal" | ||
|
||
"github.com/peterbourgon/ff/v3/ffcli" | ||
) | ||
|
||
var ( | ||
rootFlagset = flag.NewFlagSet("klimat", flag.ExitOnError) | ||
) | ||
|
||
func main() { | ||
log.SetOutput(os.Stdout) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
c := make(chan os.Signal, 1) | ||
signal.Notify(c, os.Interrupt, os.Kill) | ||
defer func() { | ||
signal.Stop(c) | ||
cancel() | ||
}() | ||
go func() { | ||
select { | ||
case <-c: | ||
log.Print("Received cancellation signal, shutting down...") | ||
cancel() | ||
case <-ctx.Done(): | ||
} | ||
}() | ||
|
||
root := &ffcli.Command{ | ||
ShortUsage: "klimat [flags] <subcommand>", | ||
LongHelp: "This CLI can be used to interact with climate devices. " + | ||
"Right now it only supports interafcing with Philips AirCombi " + | ||
"devices.", | ||
FlagSet: rootFlagset, | ||
Subcommands: []*ffcli.Command{newDiscoverCmd(os.Stdout), newPublishCmd(os.Stdout)}, | ||
Exec: func(context.Context, []string) error { | ||
return flag.ErrHelp | ||
}, | ||
} | ||
|
||
if err := root.ParseAndRun(ctx, os.Args[1:]); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.