Skip to content

Commit b6c0d69

Browse files
committed
adds the systemd command
1 parent ba36548 commit b6c0d69

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

cmd/systemd.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright © 2024 Juliano Martinez <[email protected]>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
"github.com/ncode/tagit/pkg/systemd"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
// systemdCmd represents the systemd command
25+
var systemdCmd = &cobra.Command{
26+
Use: "systemd",
27+
Short: "A brief description of your command",
28+
Long: `A longer description that spans multiple lines and likely contains examples
29+
and usage of using your command. For example:
30+
31+
Cobra is a CLI library for Go that empowers applications.
32+
This application is a tool to generate the needed files
33+
to quickly create a Cobra application.`,
34+
Run: func(cmd *cobra.Command, args []string) {
35+
fields := &systemd.Fields{
36+
User: cmd.PersistentFlags().Lookup("user").Value.String(),
37+
Group: cmd.PersistentFlags().Lookup("group").Value.String(),
38+
ConsulAddr: cmd.InheritedFlags().Lookup("consul-addr").Value.String(),
39+
ServiceID: cmd.InheritedFlags().Lookup("service-id").Value.String(),
40+
Script: cmd.InheritedFlags().Lookup("script").Value.String(),
41+
TagPrefix: cmd.InheritedFlags().Lookup("tag-prefix").Value.String(),
42+
Interval: cmd.InheritedFlags().Lookup("interval").Value.String(),
43+
Token: cmd.InheritedFlags().Lookup("token").Value.String(),
44+
}
45+
fmt.Println(systemd.RenderTemplate(fields))
46+
},
47+
}
48+
49+
func init() {
50+
rootCmd.AddCommand(systemdCmd)
51+
systemdCmd.PersistentFlags().StringP("user", "u", "nobody", "user to run the service")
52+
systemdCmd.PersistentFlags().StringP("group", "g", "nobody", "group to run the service")
53+
}

0 commit comments

Comments
 (0)