add numbering
This commit is contained in:
@@ -22,15 +22,17 @@ type Client struct {
|
||||
CourseID string
|
||||
CourseName string
|
||||
FilesOnly bool
|
||||
ModuleNumbers bool
|
||||
downloadedFiles map[string]bool
|
||||
}
|
||||
|
||||
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly bool) *Client {
|
||||
func NewClient(httpClient *http.Client, accessToken, courseID string, filesOnly, moduleNumbers bool) *Client {
|
||||
return &Client{
|
||||
HTTPClient: httpClient,
|
||||
AccessToken: accessToken,
|
||||
CourseID: courseID,
|
||||
FilesOnly: filesOnly,
|
||||
ModuleNumbers: moduleNumbers,
|
||||
downloadedFiles: make(map[string]bool),
|
||||
}
|
||||
}
|
||||
@@ -152,15 +154,20 @@ func (c *Client) DownloadModules(courseRoot string) {
|
||||
json.NewDecoder(resp.Body).Decode(&modules)
|
||||
resp.Body.Close()
|
||||
|
||||
for _, mod := range modules {
|
||||
for i, mod := range modules {
|
||||
modName := mod.Name
|
||||
if c.ModuleNumbers {
|
||||
modName = fmt.Sprintf("[%d] %s", i+1, mod.Name)
|
||||
}
|
||||
|
||||
modBaseDir := courseRoot
|
||||
if !c.FilesOnly {
|
||||
modBaseDir = filepath.Join(courseRoot, "Modules", utils.Sanitize(mod.Name))
|
||||
modBaseDir = filepath.Join(courseRoot, "Modules", utils.Sanitize(modName))
|
||||
}
|
||||
os.MkdirAll(modBaseDir, 0o755)
|
||||
|
||||
if !c.FilesOnly {
|
||||
fmt.Printf("\n[Module] %s\n", mod.Name)
|
||||
fmt.Printf("\n[Module] %s\n", modName)
|
||||
}
|
||||
|
||||
subHeaderStack := []string{}
|
||||
|
||||
Reference in New Issue
Block a user