-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix save channel on install, normalize channel names for flypkgs migr…
…ation
- Loading branch information
1 parent
090b539
commit ab66cff
Showing
5 changed files
with
92 additions
and
75 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package version | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/superfly/flyctl/internal/cache" | ||
"github.com/superfly/flyctl/internal/command" | ||
"github.com/superfly/flyctl/internal/config" | ||
"github.com/superfly/flyctl/internal/flag" | ||
"github.com/superfly/flyctl/internal/state" | ||
"github.com/superfly/flyctl/internal/update" | ||
"github.com/superfly/flyctl/iostreams" | ||
) | ||
|
||
func newSaveInstall() *cobra.Command { | ||
cmd := command.New( | ||
"save-install", | ||
"save-install", | ||
"Save installation configuration", | ||
runSaveInstall) | ||
|
||
flag.Add(cmd, | ||
flag.String{ | ||
Name: "channel", | ||
Description: "Channel to use for updates", | ||
}, | ||
) | ||
flag.Add(cmd, | ||
flag.Bool{ | ||
Name: "disable-auto-update", | ||
Description: "Disable automatic updates", | ||
}, | ||
) | ||
|
||
cmd.Hidden = true | ||
|
||
return cmd | ||
} | ||
|
||
func runSaveInstall(ctx context.Context) error { | ||
channel := flag.GetString(ctx, "channel") | ||
autoUpdateEnabled := flag.GetBool(ctx, "auto-update") | ||
|
||
return saveInstall(ctx, channel, autoUpdateEnabled) | ||
} | ||
|
||
func saveInstall(ctx context.Context, channel string, autoUpdateEnabled bool) error { | ||
io := iostreams.FromContext(ctx) | ||
cache := cache.FromContext(ctx) | ||
|
||
cache.SetChannel(update.NormalizeChannel(channel)) | ||
|
||
fmt.Fprintf(io.ErrOut, "set update hannel to %s\n", channel) | ||
|
||
// TODO[md]: This was copied from internal/command/settings/autoupdate.go... move it to a helper | ||
// so we're not doing it twice | ||
path := state.ConfigFile(ctx) | ||
if err := config.SetAutoUpdate(path, autoUpdateEnabled); err != nil { | ||
return fmt.Errorf("failed persisting %s in %s: %w", config.AutoUpdateFileKey, path, err) | ||
} | ||
return nil | ||
} |
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