-
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.
- Loading branch information
Showing
9 changed files
with
372 additions
and
9 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
121 changes: 121 additions & 0 deletions
121
app/presentation/cli/spotlike/command/spotlike/get/albums.go
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package get | ||
|
||
import ( | ||
c "github.com/spf13/cobra" | ||
|
||
spotlikeApp "github.com/yanosea/spotlike/app/application/spotlike" | ||
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/command/spotlike" | ||
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/config" | ||
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/formatter" | ||
|
||
"github.com/yanosea/spotlike/pkg/proxy" | ||
) | ||
|
||
type GetAlbumsOptions struct { | ||
Format string | ||
} | ||
|
||
var ( | ||
GetAlbumsOps = GetAlbumsOptions{ | ||
Format: "table", | ||
} | ||
) | ||
|
||
func NewAlbumCommand( | ||
cobra proxy.Cobra, | ||
conf *config.SpotlikeCliConfig, | ||
output *string, | ||
) proxy.Command { | ||
cmd := cobra.NewCommand() | ||
cmd.SetUse("albums") | ||
cmd.SetAliases([]string{"als", "a"}) | ||
cmd.SetUsageTemplate(getAlbumsUsageTemplate) | ||
cmd.SetHelpTemplate(getAlbumsHelpTemplate) | ||
cmd.SetArgs(cobra.ExactArgs(1)) | ||
cmd.SetSilenceErrors(true) | ||
cmd.Flags().StringVarP( | ||
&GetAlbumsOps.Format, | ||
"format", | ||
"f", | ||
"table", | ||
"📝 format of the output (default \"table\", e.g: \"plain\")", | ||
) | ||
|
||
cmd.SetRunE( | ||
func(_ *c.Command, args []string) error { | ||
return runAlbum(output, args, conf) | ||
}, | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func runAlbum(output *string, args []string, conf *config.SpotlikeCliConfig) error { | ||
client, err := spotlike.Auth(conf, output, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
gctuc := spotlikeApp.NewGetContentTypeUseCase(client) | ||
var albums []*spotlikeApp.GetContentTypeUseCaseOutputDto | ||
gctucDto, err := gctuc.Run(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if gctucDto.Type != spotlikeApp.Artist { | ||
o := formatter.Yellow("⚡ The id " + gctucDto.Name + " is not an artist. skipping...") | ||
*output = o | ||
return nil | ||
} | ||
|
||
gaauc := spotlikeApp.NewGetAllAlbumsByArtistIdUseCase(client) | ||
allAlbums, err := gaauc.Run(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, album := range allAlbums { | ||
album := &spotlikeApp.GetContentTypeUseCaseOutputDto{ | ||
ID: album.ID, | ||
Type: spotlikeApp.Album, | ||
Name: album.Name, | ||
Artists: album.Artists, | ||
ReleaseDate: album.ReleaseDate, | ||
} | ||
albums = append(albums, album) | ||
} | ||
|
||
f, err := formatter.NewFormatter(GetAlbumsOps.Format) | ||
if err != nil { | ||
o := formatter.Red("❌ Failed to create a formatter...") | ||
*output = o | ||
return err | ||
} | ||
o := "\n" + f.Format(albums) | ||
*output = o | ||
|
||
return nil | ||
} | ||
|
||
const ( | ||
getAlbumsHelpTemplate = `ℹ️💿 Get the information of the albums on Spotify by artist ID. | ||
You can get the information of the albums on Spotify by artist ID. | ||
Before using this command, | ||
you need to get the ID of the artist you want to get by using the search command. | ||
` + getAlbumsUsageTemplate | ||
getAlbumsUsageTemplate = `Usage: | ||
spotlike get albums [flags] [arguments] | ||
spotlike get als [flags] [arguments] | ||
spotlike get a [flags] [arguments] | ||
Flags: | ||
-f, --format 📝 format of the output (default "table", e.g: "plain") | ||
Argument: | ||
ID 🆔 ID of the artist (e.g. : "00DuPiLri3mNomvvM3nZvU") | ||
` | ||
) |
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package get | ||
|
||
import ( | ||
c "github.com/spf13/cobra" | ||
|
||
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/config" | ||
"github.com/yanosea/spotlike/app/presentation/cli/spotlike/formatter" | ||
|
||
"github.com/yanosea/spotlike/pkg/proxy" | ||
) | ||
|
||
func NewGetCommand( | ||
cobra proxy.Cobra, | ||
conf *config.SpotlikeCliConfig, | ||
output *string, | ||
) proxy.Command { | ||
cmd := cobra.NewCommand() | ||
cmd.SetUse("get") | ||
cmd.SetAliases([]string{"ge", "g"}) | ||
cmd.SetUsageTemplate(getUsageTemplate) | ||
cmd.SetHelpTemplate(getHelpTemplate) | ||
cmd.SetArgs(cobra.ExactArgs(0)) | ||
cmd.SetSilenceErrors(true) | ||
cmd.AddCommand( | ||
NewAlbumCommand( | ||
cobra, | ||
conf, | ||
output, | ||
), | ||
NewTrackCommand( | ||
cobra, | ||
conf, | ||
output, | ||
), | ||
) | ||
|
||
cmd.SetRunE( | ||
func(cmd *c.Command, args []string) error { | ||
return runGet(output) | ||
}, | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func runGet(output *string) error { | ||
o := formatter.Yellow(`⚡ Use sub command below... | ||
- 💿 album | ||
- 🎵 track | ||
Use "spotlike get --help" for more information about spotlike get. | ||
Use "spotlike get [command] --help" for more information about a command. | ||
`) | ||
*output = o | ||
|
||
return nil | ||
} | ||
|
||
const ( | ||
getHelpTemplate = `ℹ️ Get the information of the content on Spotify by ID. | ||
You can get the information of the content on Spotify by ID. | ||
Before using this command, | ||
you need to get the ID of the content you want to get by using the search command. | ||
` + getUsageTemplate | ||
getUsageTemplate = `Usage: | ||
spotlike get [flags] | ||
spotlike ge [flags] | ||
spotlike g [flags] | ||
spotlike get [command] | ||
spotlike ge [command] | ||
spotlike g [command] | ||
Available Commands: | ||
albums, als, a 💿 Get the information of the albums on Spotify by ID. | ||
tracks, trs, t 🎵 Get the information of the tracks on Spotify by ID. | ||
Flags: | ||
-h, --help 🤝 help for like | ||
Use "spotlike get [command] --help" for more information about a command. | ||
` | ||
) |
Oops, something went wrong.