Skip to content

Commit 6f20707

Browse files
committed
feat: add ulrs command
1 parent a48f63d commit 6f20707

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- [Usage](#usage)
1111
- [Generating Reports of Assignments](#generating-reports-of-assignments)
1212
- [Cloning Repos](#cloning-repos)
13+
- [Getting URLs](#getting-urls)
1314
- [Seeding using a custom tool](#seeding-using-a-custom-tool)
1415
- [Example using `seeder` Option](#example-using-seeder-option)
1516
- [Using starter code as a template](#using-starter-code-as-a-template)
@@ -180,6 +181,7 @@ Usage:
180181
Available Commands:
181182
check check course config
182183
clone Clone repositories.
184+
completion Generate the autocompletion script for the specified shell
183185
delete Delete repositories.
184186
generate Generate repositories.
185187
help Help about any command
@@ -188,6 +190,7 @@ Available Commands:
188190
setaccess Set access level for exisiting repositories.
189191
show Show config of an assignment
190192
update Update repositories with code.
193+
urls get urls for repositories
191194
version Print the version number of Glabs
192195
193196
Flags:
@@ -263,6 +266,29 @@ glabs clone algdati blatt3 "grp0[35]" -fs | xargs code
263266

264267
clones the two repositories for `grp03` and `grp05` and opens them in VS Code.
265268

269+
## Getting URLs
270+
271+
```
272+
get urls for repositories for each student or group in course for assignment.
273+
You can specify students or groups in order to get an url only for these.
274+
275+
Usage:
276+
glabs urls course assignment [groups...|students...] [flags]
277+
278+
Flags:
279+
-h, --help help for urls
280+
281+
Global Flags:
282+
--config string config file (default is $HOME/.glabs.yml)
283+
-v, --verbose verbose output
284+
```
285+
286+
This is useful for opening the webpages using a pipe, e.g.,
287+
288+
```
289+
glabs urls algdati blatt3 grp15 | xargs open
290+
```
291+
266292
## Seeding using a custom tool
267293

268294
Instead of providing each student/group the same repository using the startercode option it is possible to run a tool to seed each repository individually.

cmd/urls.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cmd
2+
3+
import (
4+
"github.com/obcode/glabs/config"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
var (
9+
urlsCmd = &cobra.Command{
10+
Use: "urls course assignment [groups...|students...]",
11+
Short: "get urls for repositories",
12+
Long: `get urls for repositories for each student or group in course for assignment.
13+
You can specify students or groups in order to get an url only for these.`,
14+
Args: cobra.MinimumNArgs(2), //nolint:gomnd
15+
Run: func(cmd *cobra.Command, args []string) {
16+
assignmentConfig := config.GetAssignmentConfig(args[0], args[1], args[2:]...)
17+
assignmentConfig.Urls()
18+
},
19+
}
20+
)
21+
22+
func init() {
23+
rootCmd.AddCommand(urlsCmd)
24+
}

config/urls.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package config
2+
3+
import "fmt"
4+
5+
func (cfg *AssignmentConfig) Urls() {
6+
if cfg.Per == PerStudent {
7+
for _, stud := range cfg.Students {
8+
fmt.Printf("%s/%s-%s\n", cfg.URL, cfg.Name, cfg.RepoSuffix(stud))
9+
}
10+
} else { // PerGroup
11+
for _, group := range cfg.Groups {
12+
fmt.Printf("%s/%s-%s\n", cfg.URL, cfg.Name, group.Name)
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)