Skip to content

Commit 99edf3f

Browse files
authored
Add flag for number periods gathering/posting data (#176)
* Add flag for number periods gathering/posting data Number of periods is integer. Takes -1 as default (runs perpetually) - Any -ve will do this Signed-off-by: Jamie Leppard <[email protected]> * Adds one-shot flag to run agent a single time Signed-off-by: Jamie Leppard <[email protected]> * One-shot flag w/ break and no short option Signed-off-by: Jamie Leppard <[email protected]> Co-authored-by: jamie <JammyL> Co-authored-by: Jamie Leppard <[email protected]>
1 parent 911e388 commit 99edf3f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cmd/agent.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,12 @@ func init() {
5757
"",
5858
"Location of the credentials file. For OAuth2 based authentication.",
5959
)
60+
agentCmd.PersistentFlags().BoolVarP(
61+
&agent.OneShot,
62+
"one-shot",
63+
"",
64+
false,
65+
"Runs agent a single time if true, or continously if false",
66+
)
67+
6068
}

pkg/agent/run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ var AuthToken string
2828
// Period is the number of seconds between scans
2929
var Period uint
3030

31+
// Agent will run only once if OneShot is enabled
32+
var OneShot bool
33+
3134
// CredentialsPath is where the agent will try to loads the credentials. (Experimental)
3235
var CredentialsPath string
3336

37+
3438
// Run starts the agent process
3539
func Run(cmd *cobra.Command, args []string) {
3640
ctx := context.Background()
37-
3841
for {
3942
gatherAndPostData(ctx)
43+
if OneShot {
44+
break
45+
}
4046
time.Sleep(time.Duration(Period) * time.Second)
4147
}
4248
}

0 commit comments

Comments
 (0)