Commit b062f015 authored by ale's avatar ale

Make some things private

parent 4d07f9a7
...@@ -117,22 +117,22 @@ func (v *floatOptionalValue) Get() interface{} { ...@@ -117,22 +117,22 @@ func (v *floatOptionalValue) Get() interface{} {
return v.value return v.value
} }
type HasAddFlags interface { type hasAddFlags interface {
AddFlags(*gonutsflag.FlagSet) AddFlags(*gonutsflag.FlagSet)
} }
type CommandInterface interface { type commandInterface interface {
Run([]string) Run([]string)
Command() *commander.Command Command() *commander.Command
} }
type BaseCommand struct { type baseCommand struct {
UsageLine string UsageLine string
Short string Short string
Long string Long string
} }
func (b *BaseCommand) Command() *commander.Command { func (b *baseCommand) Command() *commander.Command {
return &commander.Command{ return &commander.Command{
UsageLine: b.UsageLine, UsageLine: b.UsageLine,
Short: b.Short, Short: b.Short,
...@@ -140,7 +140,7 @@ func (b *BaseCommand) Command() *commander.Command { ...@@ -140,7 +140,7 @@ func (b *BaseCommand) Command() *commander.Command {
} }
} }
func (b *BaseCommand) Run(args []string) { func (b *baseCommand) Run(args []string) {
} }
var auClient *client.Client var auClient *client.Client
...@@ -159,14 +159,14 @@ func getClient() *client.Client { ...@@ -159,14 +159,14 @@ func getClient() *client.Client {
return auClient return auClient
} }
func setRelay(m *pb.Mount, relayUrl string) { func setRelay(m *pb.Mount, relayURL string) {
if relayUrl == "" { if relayURL == "" {
// Randomly generate source credentials. // Randomly generate source credentials.
m.SourceUsername = autoradio.GenerateUsername(m.Path) m.SourceUsername = autoradio.GenerateUsername(m.Path)
m.SourcePassword = autoradio.GeneratePassword() m.SourcePassword = autoradio.GeneratePassword()
} else { } else {
// Validate the given relay URL. // Validate the given relay URL.
u, err := url.Parse(relayUrl) u, err := url.Parse(relayURL)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
...@@ -213,14 +213,14 @@ func mountExists(name string, c *client.Client) bool { ...@@ -213,14 +213,14 @@ func mountExists(name string, c *client.Client) bool {
// Create a new mountpoint. // Create a new mountpoint.
type createMountCommand struct { type createMountCommand struct {
BaseCommand baseCommand
relay string relay string
fallback string fallback string
} }
func newCreateMountCommand() *createMountCommand { func newCreateMountCommand() *createMountCommand {
return &createMountCommand{ return &createMountCommand{
BaseCommand: BaseCommand{ baseCommand: baseCommand{
UsageLine: "create-mount <path>", UsageLine: "create-mount <path>",
Short: "Create a new mountpoint", Short: "Create a new mountpoint",
Long: ` Long: `
...@@ -273,7 +273,7 @@ func (cmd *createMountCommand) Run(args []string) { ...@@ -273,7 +273,7 @@ func (cmd *createMountCommand) Run(args []string) {
// Create a submount (transcoded stream). // Create a submount (transcoded stream).
type createTranscodingMountCommand struct { type createTranscodingMountCommand struct {
BaseCommand baseCommand
sourcePath string sourcePath string
format string format string
...@@ -287,7 +287,7 @@ type createTranscodingMountCommand struct { ...@@ -287,7 +287,7 @@ type createTranscodingMountCommand struct {
func newCreateTranscodingMountCommand() *createTranscodingMountCommand { func newCreateTranscodingMountCommand() *createTranscodingMountCommand {
return &createTranscodingMountCommand{ return &createTranscodingMountCommand{
BaseCommand: BaseCommand{ baseCommand: baseCommand{
UsageLine: "create-transcoding-mount <path>", UsageLine: "create-transcoding-mount <path>",
Short: "Create a transcoding mount", Short: "Create a transcoding mount",
Long: ` Long: `
...@@ -302,7 +302,7 @@ func (cmd *createTranscodingMountCommand) AddFlags(f *gonutsflag.FlagSet) { ...@@ -302,7 +302,7 @@ func (cmd *createTranscodingMountCommand) AddFlags(f *gonutsflag.FlagSet) {
f.StringVar(&cmd.sourcePath, "source", "", "Source mountpoint") f.StringVar(&cmd.sourcePath, "source", "", "Source mountpoint")
f.StringVar(&cmd.format, "codec", "mp3", "Encoding format") f.StringVar(&cmd.format, "codec", "mp3", "Encoding format")
f.Float64Var(&cmd.quality, "quality", 0, "Quality (for VBR encoders)") f.Float64Var(&cmd.quality, "quality", 0, "Quality (for VBR encoders)")
f.IntVar(&cmd.bitRate, "bitrate", 32, "Bitrate (kbps)") f.IntVar(&cmd.bitRate, "bitrate", 32, "Bitrate (Kbps)")
f.IntVar(&cmd.sampleRate, "samplerate", 44100, "Sample rate (Hz)") f.IntVar(&cmd.sampleRate, "samplerate", 44100, "Sample rate (Hz)")
f.IntVar(&cmd.channels, "channels", 2, "Number of channels") f.IntVar(&cmd.channels, "channels", 2, "Number of channels")
f.StringVar(&cmd.stereoMode, "stereo-mode", "joint_stereo", "Stereo mode for mp3 codec (stereo, joint_stereo)") f.StringVar(&cmd.stereoMode, "stereo-mode", "joint_stereo", "Stereo mode for mp3 codec (stereo, joint_stereo)")
...@@ -360,7 +360,7 @@ func (cmd *createTranscodingMountCommand) Run(args []string) { ...@@ -360,7 +360,7 @@ func (cmd *createTranscodingMountCommand) Run(args []string) {
// Edit a mountpoint. // Edit a mountpoint.
type editMountCommand struct { type editMountCommand struct {
BaseCommand baseCommand
relay *stringOptionalValue relay *stringOptionalValue
fallback *stringOptionalValue fallback *stringOptionalValue
transFormat *stringOptionalValue transFormat *stringOptionalValue
...@@ -376,7 +376,7 @@ var UNSET = "UNSET" ...@@ -376,7 +376,7 @@ var UNSET = "UNSET"
func newEditMountCommand() *editMountCommand { func newEditMountCommand() *editMountCommand {
return &editMountCommand{ return &editMountCommand{
BaseCommand: BaseCommand{ baseCommand: baseCommand{
UsageLine: "edit-mount <path>", UsageLine: "edit-mount <path>",
Short: "Edit an existing mountpoint", Short: "Edit an existing mountpoint",
Long: ` Long: `
...@@ -406,7 +406,7 @@ func (cmd *editMountCommand) AddFlags(f *gonutsflag.FlagSet) { ...@@ -406,7 +406,7 @@ func (cmd *editMountCommand) AddFlags(f *gonutsflag.FlagSet) {
f.Var(cmd.transSource, "source", "[transcoding] Source mountpoint") f.Var(cmd.transSource, "source", "[transcoding] Source mountpoint")
f.Var(cmd.transFormat, "codec", "[transcoding] Encoding format") f.Var(cmd.transFormat, "codec", "[transcoding] Encoding format")
f.Var(cmd.transQuality, "quality", "[transcoding] Quality (for VBR encoders)") f.Var(cmd.transQuality, "quality", "[transcoding] Quality (for VBR encoders)")
f.Var(cmd.transBitRate, "bitrate", "[transcoding] Bitrate (kbps)") f.Var(cmd.transBitRate, "bitrate", "[transcoding] Bitrate (Kbps)")
f.Var(cmd.transSampleRate, "samplerate", "[transcoding] Sample rate (Hz)") f.Var(cmd.transSampleRate, "samplerate", "[transcoding] Sample rate (Hz)")
f.Var(cmd.transChannels, "channels", "[transcoding] Number of channels") f.Var(cmd.transChannels, "channels", "[transcoding] Number of channels")
f.Var(cmd.transStereoMode, "stereo-mode", "[transcoding] Stereo mode for mp3 encoding (stereo, joint_stereo)") f.Var(cmd.transStereoMode, "stereo-mode", "[transcoding] Stereo mode for mp3 encoding (stereo, joint_stereo)")
...@@ -489,12 +489,12 @@ func (cmd *editMountCommand) Run(args []string) { ...@@ -489,12 +489,12 @@ func (cmd *editMountCommand) Run(args []string) {
// Delete an existing mountpoint. // Delete an existing mountpoint.
type deleteMountCommand struct { type deleteMountCommand struct {
BaseCommand baseCommand
} }
func newDeleteMountCommand() *deleteMountCommand { func newDeleteMountCommand() *deleteMountCommand {
return &deleteMountCommand{ return &deleteMountCommand{
BaseCommand{ baseCommand{
UsageLine: "delete-mount <path>", UsageLine: "delete-mount <path>",
Short: "Delete a mountpoint", Short: "Delete a mountpoint",
Long: ` Long: `
...@@ -537,12 +537,12 @@ func (cmd *deleteMountCommand) Run(args []string) { ...@@ -537,12 +537,12 @@ func (cmd *deleteMountCommand) Run(args []string) {
// List known mountpoints. // List known mountpoints.
type listMountsCommand struct { type listMountsCommand struct {
BaseCommand baseCommand
} }
func newListMountsCommand() *listMountsCommand { func newListMountsCommand() *listMountsCommand {
return &listMountsCommand{ return &listMountsCommand{
BaseCommand{ baseCommand{
UsageLine: "list-mounts", UsageLine: "list-mounts",
Short: "List all configured mountpoints", Short: "List all configured mountpoints",
Long: ` Long: `
...@@ -581,12 +581,12 @@ func (cmd *listMountsCommand) Run(args []string) { ...@@ -581,12 +581,12 @@ func (cmd *listMountsCommand) Run(args []string) {
// Show mountpoint information. // Show mountpoint information.
type showMountCommand struct { type showMountCommand struct {
BaseCommand baseCommand
} }
func newShowMountCommand() *showMountCommand { func newShowMountCommand() *showMountCommand {
return &showMountCommand{ return &showMountCommand{
BaseCommand{ baseCommand{
UsageLine: "show-mount <path>", UsageLine: "show-mount <path>",
Short: "Show mountpoint information", Short: "Show mountpoint information",
Long: ` Long: `
...@@ -615,12 +615,12 @@ func (cmd *showMountCommand) Run(args []string) { ...@@ -615,12 +615,12 @@ func (cmd *showMountCommand) Run(args []string) {
// Backup mount configuration. // Backup mount configuration.
type backupCommand struct { type backupCommand struct {
BaseCommand baseCommand
} }
func newBackupCommand() *backupCommand { func newBackupCommand() *backupCommand {
return &backupCommand{ return &backupCommand{
BaseCommand{ baseCommand{
UsageLine: "backup", UsageLine: "backup",
Short: "Backup mount configuration", Short: "Backup mount configuration",
Long: ` Long: `
...@@ -647,12 +647,12 @@ func (cmd *backupCommand) Run(args []string) { ...@@ -647,12 +647,12 @@ func (cmd *backupCommand) Run(args []string) {
// Restore mount configuration. // Restore mount configuration.
type restoreCommand struct { type restoreCommand struct {
BaseCommand baseCommand
} }
func newRestoreCommand() *restoreCommand { func newRestoreCommand() *restoreCommand {
return &restoreCommand{ return &restoreCommand{
BaseCommand{ baseCommand{
UsageLine: "restore", UsageLine: "restore",
Short: "Restore mount configuration", Short: "Restore mount configuration",
Long: ` Long: `
...@@ -685,13 +685,13 @@ var cmdr = &commander.Command{ ...@@ -685,13 +685,13 @@ var cmdr = &commander.Command{
Short: "Manage `autoradio' configuration", Short: "Manage `autoradio' configuration",
} }
func addCommand(c CommandInterface) { func addCommand(c commandInterface) {
cmd := c.Command() cmd := c.Command()
cmd.Run = func(unused *commander.Command, args []string) error { cmd.Run = func(unused *commander.Command, args []string) error {
c.Run(args) c.Run(args)
return nil return nil
} }
if afc, ok := c.(HasAddFlags); ok { if afc, ok := c.(hasAddFlags); ok {
afc.AddFlags(&cmd.Flag) afc.AddFlags(&cmd.Flag)
} }
cmdr.Subcommands = append(cmdr.Subcommands, cmd) cmdr.Subcommands = append(cmdr.Subcommands, cmd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment