|
| 1 | +package libraries |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "strconv" |
| 6 | + |
| 7 | + "path/filepath" |
| 8 | + |
| 9 | + "strings" |
| 10 | + |
| 11 | + "github.com/arduino/arduino-cli/config" |
| 12 | + "github.com/arduino/arduino-cli/opts" |
| 13 | +) |
| 14 | + |
| 15 | +type libsCommand struct { |
| 16 | + List libsListCommand `command:"list" description:"List/search available libraries"` |
| 17 | +} |
| 18 | + |
| 19 | +/* |
| 20 | +func (*libsCommand) Usage() string { |
| 21 | + return "[--board package:arch:board[:parameters]] [--pref name=value] [-v|--verbose] [--preserve-temp-files] <FILE.ino>" |
| 22 | +} |
| 23 | +*/ |
| 24 | + |
| 25 | +var options libsCommand |
| 26 | + |
| 27 | +func init() { |
| 28 | + opts.Parser.AddCommand("libs", "Manages libraries", "alsdkmaslkdmaslkdm", &options) |
| 29 | +} |
| 30 | + |
| 31 | +type libsListCommand struct { |
| 32 | + Long []bool `long:"long" short:"l" description:"Output detailed information about libraries (use twice for even more verbose output)"` |
| 33 | +} |
| 34 | + |
| 35 | +func (*libsListCommand) Usage() string { |
| 36 | + return "[-l] [-l] [<libname>]" |
| 37 | +} |
| 38 | + |
| 39 | +func (r *Release) String() string { |
| 40 | + res := " Release: " + r.Version + "\n" |
| 41 | + res += " URL: " + r.URL + "\n" |
| 42 | + res += " ArchiveFileName: " + r.ArchiveFileName + "\n" |
| 43 | + res += " Size: " + strconv.Itoa(r.Size) + "\n" |
| 44 | + res += " Checksum: " + r.Checksum + "\n" |
| 45 | + return res |
| 46 | +} |
| 47 | + |
| 48 | +func (l *Library) String() string { |
| 49 | + res := "Name: " + l.Name + "\n" |
| 50 | + res += " Author: " + l.Author + "\n" |
| 51 | + res += " Maintainer: " + l.Maintainer + "\n" |
| 52 | + res += " Sentence: " + l.Sentence + "\n" |
| 53 | + res += " Paragraph: " + l.Paragraph + "\n" |
| 54 | + res += " Website: " + l.Website + "\n" |
| 55 | + res += " Category: " + l.Category + "\n" |
| 56 | + res += " Architecture: " + strings.Join(l.Architectures, ", ") + "\n" |
| 57 | + res += " Types: " + strings.Join(l.Types, ", ") + "\n" |
| 58 | + res += " Versions: " + strings.Join(l.Versions(), ", ") + "\n" |
| 59 | + return res |
| 60 | +} |
| 61 | + |
| 62 | +func (opts *libsListCommand) Execute(args []string) error { |
| 63 | + fmt.Println("libs list:", args) |
| 64 | + fmt.Println("long =", opts.Long) |
| 65 | + |
| 66 | + baseFolder, err := config.GetDefaultArduinoFolder() |
| 67 | + if err != nil { |
| 68 | + return fmt.Errorf("Could not determine data folder: %s", err) |
| 69 | + } |
| 70 | + |
| 71 | + libFile := filepath.Join(baseFolder, "library_index.json") |
| 72 | + index, err := LoadLibrariesIndex(libFile) |
| 73 | + if err != nil { |
| 74 | + return fmt.Errorf("Could not read library index: %s", err) |
| 75 | + } |
| 76 | + |
| 77 | + libraries, err := CreateStatusContextFromIndex(index, nil, nil) |
| 78 | + if err != nil { |
| 79 | + return fmt.Errorf("Could not synchronize library status: %s", err) |
| 80 | + } |
| 81 | + |
| 82 | + for _, name := range libraries.Names() { |
| 83 | + if len(opts.Long) > 0 { |
| 84 | + lib := libraries.Libraries[name] |
| 85 | + fmt.Print(lib) |
| 86 | + if len(opts.Long) > 1 { |
| 87 | + for _, r := range lib.Releases { |
| 88 | + fmt.Print(r) |
| 89 | + } |
| 90 | + } |
| 91 | + fmt.Println() |
| 92 | + } else { |
| 93 | + fmt.Println(name) |
| 94 | + } |
| 95 | + } |
| 96 | + return nil |
| 97 | +} |
0 commit comments