Skip to content

Commit f31e960

Browse files
authored
Merge pull request #321 from wakatime/feature/useragent-display
Add `--useragent` flag
2 parents 1c5aa7c + 7e9d2bb commit f31e960

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

cmd/legacy/run.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ package legacy
22

33
import (
44
"errors"
5+
"fmt"
56
"os"
67

78
"github.com/wakatime/wakatime-cli/cmd/legacy/configread"
89
"github.com/wakatime/wakatime-cli/cmd/legacy/configwrite"
9-
"github.com/wakatime/wakatime-cli/cmd/legacy/heartbeat"
10+
heartbeatcmd "github.com/wakatime/wakatime-cli/cmd/legacy/heartbeat"
1011
"github.com/wakatime/wakatime-cli/cmd/legacy/logfile"
1112
"github.com/wakatime/wakatime-cli/cmd/legacy/today"
1213
"github.com/wakatime/wakatime-cli/cmd/legacy/todaygoal"
1314
"github.com/wakatime/wakatime-cli/pkg/config"
1415
"github.com/wakatime/wakatime-cli/pkg/exitcode"
16+
"github.com/wakatime/wakatime-cli/pkg/heartbeat"
1517
"github.com/wakatime/wakatime-cli/pkg/log"
1618

1719
"github.com/spf13/viper"
@@ -43,6 +45,20 @@ func Run(v *viper.Viper) {
4345
log.SetOutput(f)
4446
log.SetVerbose(logfileParams.Verbose)
4547

48+
if v.GetBool("useragent") {
49+
log.Debugln("command: useragent")
50+
51+
if plugin := v.GetString("plugin"); plugin != "" {
52+
fmt.Println(heartbeat.UserAgent(plugin))
53+
54+
os.Exit(exitcode.Success)
55+
}
56+
57+
fmt.Println(heartbeat.UserAgentUnknownPlugin())
58+
59+
os.Exit(exitcode.Success)
60+
}
61+
4662
if v.GetBool("version") {
4763
log.Debugln("command: version")
4864

@@ -77,5 +93,5 @@ func Run(v *viper.Viper) {
7793

7894
log.Debugln("command: heartbeat")
7995

80-
heartbeat.Run(v)
96+
heartbeatcmd.Run(v)
8197
}

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func setFlags(cmd *cobra.Command, v *viper.Viper) {
173173
"",
174174
"Prints time for the given goal id Today, then exits"+
175175
" Visit wakatime.com/api/v1/users/current/goals to find your goal id.")
176+
flags.Bool("useragent", false, "Prints the wakatime-cli useragent, as it will be sent to the api, then exits.")
176177
flags.Bool("verbose", false, "Turns on debug messages in log file.")
177178
flags.Bool("version", false, "Prints the wakatime-cli version number, then exits.")
178179
flags.Bool("write", false, "When set, tells api this heartbeat was triggered from writing to a file.")

0 commit comments

Comments
 (0)