forked from ribice/glice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
update
, report save
, version
and verify
commands
- `glice update` updates glice.yaml with new additions. (TODO: Add --update to `glice audit`) - `glice report save` writes dependencies to ascii table, JSON, YAML or CSV format. (TODO: Add HTML?) - `glice version` just outputs the current version in 'Glice vN.N.N' format. - `glice verify` just loads the `glice.yaml` file. This may be removed later. - Also refactored to support `thanks` and `licenses` commands, but not tested yet.
- Loading branch information
Mike Schinkel
committed
Oct 23, 2022
1 parent
1fc8db2
commit c27d0e0
Showing
49 changed files
with
1,129 additions
and
764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
glice "github.com/ribice/glice/v3/pkg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const DefaultLicensesPath = "licenses" | ||
|
||
// licensesCmd represents the licenses command | ||
var licensesCmd = &cobra.Command{ | ||
Use: "licenses", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("licenses called") | ||
}, | ||
Run: RunLicenses, | ||
Short: "Write licenses for each dependency to a file", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(licensesCmd) | ||
saveCmd.Flags().String("path", | ||
DefaultLicensesPath, | ||
fmt.Sprintf("Directory path in which to write licenses. Can be relative to %s, or absolute.", | ||
glice.ProjectFilename)) | ||
} | ||
|
||
// Here you will define your flags and configuration settings. | ||
//goland:noinspection GoUnusedParameter | ||
func RunLicenses(cmd *cobra.Command, args []string) { | ||
dir := glice.Flag(cmd, "path") | ||
ctx := context.Background() | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// licensesCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
NoteBegin() | ||
Notef("\nWriting Licenses to %s", dir) | ||
deps := ScanDependencies(ctx) | ||
SavingLicenses(deps, dir) | ||
NoteEnd() | ||
} | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// licensesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
func SavingLicenses(deps glice.Dependencies, dir string) { | ||
Notef("\nSaving Licenses") | ||
err := deps.SaveLicenses(dir, func(dep *glice.Dependency, fp string) { | ||
Infof("\nSaving license for %s to %s", dep.Import, fp) | ||
}) | ||
if err != nil { | ||
Failf(glice.ExitCannotSaveFile, | ||
"\nUnable to write licenses for individual files; %w", | ||
err) | ||
} | ||
Notef("\nLicenses saved") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
glice "github.com/ribice/glice/v3/pkg" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
DefaultReportFilename = "glice-dependencies-report.txt" | ||
DefaultReportFormat = glice.TableFormat | ||
) | ||
|
||
// saveCmd represents the save command | ||
var saveCmd = &cobra.Command{ | ||
Use: "save", | ||
Short: "A brief description of your command", | ||
Long: `A longer description that spans multiple lines and likely contains examples | ||
and usage of using your command. For example: | ||
Cobra is a CLI library for Go that empowers applications. | ||
This application is a tool to generate the needed files | ||
to quickly create a Cobra application.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("save called") | ||
}, | ||
Run: RunReportSave, | ||
Short: fmt.Sprintf("Save a report to file in %s, %s or %s format", glice.TableFormat, glice.JSONFormat, glice.CSVFormat), | ||
} | ||
|
||
func init() { | ||
reportCmd.AddCommand(saveCmd) | ||
saveCmd.Flags().String("filename", DefaultReportFilename, "File to save the license report to") | ||
saveCmd.Flags().String("format", string(DefaultReportFormat), fmt.Sprintf("Format in which to save report: %s, %s or %s", glice.TableFormat, glice.JSONFormat, glice.CSVFormat)) | ||
saveCmd.MarkFlagsMutuallyExclusive("filename", "format") | ||
} | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// saveCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// saveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
//goland:noinspection GoUnusedParameter | ||
func RunReportSave(cmd *cobra.Command, args []string) { | ||
NoteBegin() | ||
Notef("\nGenerating report to save") | ||
ctx := context.Background() | ||
adapter := GetReportWriterAdapter(cmd) | ||
adapter.SetDependencies(ScanDependencies(ctx)) | ||
WriteReport(adapter) | ||
Notef("\nReport generated") | ||
NoteEnd() | ||
} |
Oops, something went wrong.