Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 9550a44

Browse files
committed
Add identify command
1 parent 3627d50 commit 9550a44

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

cmd/identify.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
8+
"github.com/andrew-d/go-termutil"
9+
"github.com/pborman/getopt"
10+
"github.com/stilvoid/please/parsers"
11+
)
12+
13+
func init() {
14+
Commands["identify"] = identifyCommand
15+
}
16+
17+
func identifyHelp() {
18+
fmt.Println("Usage: please identify")
19+
fmt.Println()
20+
fmt.Println("Identifies the format of the structured data on standard input")
21+
}
22+
23+
func identifyCommand(args []string) {
24+
opts := getopt.CommandLine
25+
26+
opts.SetUsage(identifyHelp)
27+
28+
if termutil.Isatty(os.Stdin.Fd()) {
29+
getopt.Usage()
30+
os.Exit(1)
31+
}
32+
33+
var err error
34+
35+
// Read from stdin
36+
input, err := ioutil.ReadAll(os.Stdin)
37+
if err != nil {
38+
fmt.Fprintln(os.Stderr, "Error reading input")
39+
os.Exit(1)
40+
}
41+
42+
format, _, err := parsers.Identify(input)
43+
44+
if err != nil {
45+
fmt.Fprintln(os.Stderr, err)
46+
os.Exit(1)
47+
}
48+
49+
fmt.Println(format)
50+
}

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ func printHelp() {
1111
fmt.Println("Usage: please <COMMAND> [arg...]")
1212
fmt.Println()
1313
fmt.Println("Commands:")
14+
fmt.Println(" identify Identify the structured data on stdin")
1415
fmt.Println(" request Make a web request and output the result")
1516
fmt.Println(" respond Listen for a web request and respond to it")
1617
fmt.Println(" parse Get values from structured data and convert between formats")

0 commit comments

Comments
 (0)