Skip to content

Commit c7d6139

Browse files
authored
Merge pull request #341 from dmur1/add-command-to-set-query-task-description-#332
add a command to set/query a task's description
2 parents 4c2d3fe + 22378b7 commit c7d6139

File tree

4 files changed

+96
-3
lines changed

4 files changed

+96
-3
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,25 @@ the ctftime urls will be used to aid in the generation of writeups with the `wri
203203

204204
---
205205

206-
### 🐋 <u>d</u>ocker
206+
### 🌹 <u>de</u>scription
207+
208+
```
209+
$ ret description [task-description]
210+
```
211+
212+
set or query a task's description with ret
213+
214+
supply no arguments to see the current description
215+
216+
note that task metadata is stored in hidden directory `.ret` and therefore scoped to the cwd
217+
218+
task metadata is stored in the `.ret/task.json` file
219+
220+
🔗 https://github.com/rerrorctf/ret/blob/main/commands/description.go
221+
222+
---
223+
224+
### 🐋 <u>do</u>cker
207225

208226
```
209227
$ ret docker [ip] [port]

commands/description.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package commands
2+
3+
import (
4+
"fmt"
5+
"ret/config"
6+
"ret/theme"
7+
"ret/util"
8+
)
9+
10+
func init() {
11+
Commands = append(Commands, Command{
12+
Name: "description",
13+
Emoji: "🌹", // a rose by any other name would smell as 1337
14+
Func: Description,
15+
Help: DescriptionHelp,
16+
Arguments: []Argument{
17+
{
18+
Name: "task-description",
19+
Optional: true,
20+
List: false,
21+
},
22+
},
23+
SeeAlso: nil})
24+
}
25+
26+
func DescriptionHelp() string {
27+
return "set or query a task's description with ret\n\n" +
28+
"supply no arguments to see the current description\n\n" +
29+
"note that task metadata is stored in hidden directory " + theme.ColorCyan + "`.ret`" + theme.ColorReset + " and therefore scoped to the cwd\n\n" +
30+
"task metadata is stored in the " + theme.ColorCyan + "`" + config.TaskFileName + "`" + theme.ColorReset + " file\n"
31+
}
32+
33+
func displayCurrentTaskDescription() {
34+
description := util.GetCurrentTaskDescription()
35+
if len(description) == 0 {
36+
return
37+
}
38+
39+
fmt.Printf("🌹 "+theme.ColorBlue+"%s"+theme.ColorReset+"\n", description)
40+
}
41+
42+
func setCurrentTaskDescription(newDescription string) {
43+
oldDescription := util.GetCurrentTaskDescription()
44+
45+
if len(oldDescription) > 0 {
46+
fmt.Printf(theme.ColorGray+"🌹 changing description from: "+theme.ColorRed+"%s"+theme.ColorGray+" to: "+theme.ColorGreen+"%s"+theme.ColorReset+"\n", oldDescription, newDescription)
47+
} else {
48+
fmt.Printf(theme.ColorGray+"🌹 setting description to: "+theme.ColorGreen+"%s"+theme.ColorReset+"\n", newDescription)
49+
}
50+
51+
util.SetCurrentTaskDescription(newDescription)
52+
}
53+
54+
func Description(args []string) {
55+
if len(args) == 0 {
56+
displayCurrentTaskDescription()
57+
return
58+
}
59+
60+
util.EnsureSkeleton()
61+
62+
setCurrentTaskDescription(args[0])
63+
}

data/task.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package data
22

33
type Task struct {
4-
Name string `json:"name"`
5-
Category string `json:"category"`
4+
Name string `json:"name"`
5+
Category string `json:"category"`
6+
Description string `json:"description"`
67
}

util/task.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,14 @@ func SetCurrentTaskCategory(category string) {
5858
task.Category = category
5959
SetCurrentTask(&task)
6060
}
61+
62+
func GetCurrentTaskDescription() string {
63+
task := GetCurrentTask()
64+
return task.Description
65+
}
66+
67+
func SetCurrentTaskDescription(description string) {
68+
task := GetCurrentTask()
69+
task.Description = description
70+
SetCurrentTask(&task)
71+
}

0 commit comments

Comments
 (0)