Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Deprecate Property to Watch Flag (Issue #3256) #3440

Merged
merged 5 commits into from Jun 12, 2020

Conversation

abdullahzameek
Copy link
Contributor

@abdullahzameek abdullahzameek commented Jun 11, 2020

Fixes #3256

I've added the deprecate property to the watch flag. The result of doing so is as follows:

When "--watch" is used:
depracated-terminal

When there's no "--watch" included:
nowatch

@abdullahzameek abdullahzameek linked an issue Jun 11, 2020 that may be closed by this pull request
@abdullahzameek abdullahzameek changed the title added deprecate to watch flag Added Deprecate Property to Watch Flag (Issue #3256) Jun 11, 2020
Copy link
Member

@nicks nicks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I didn't even know about this API.

Does it work ok with --hud=true?

@abdullahzameek
Copy link
Contributor Author

abdullahzameek commented Jun 11, 2020

Nice! I didn't even know about this API.

Does it work ok with --hud=true?

@nicks So, for --hud=true, it just shows up like this:
Screenshot from 2020-06-11 18-03-27

You see it momentarily, and the terminal window switches to the tilt build progress window. It doesn't show up in the actual hud logs, but once you exit the hud, it just shows up below "tilt up" on the terminal

@nicks
Copy link
Member

nicks commented Jun 11, 2020

oof, that's frustrating.

if you want to merge this pr as-is and iterate on it, that's fine.

if you look at how tilt up is implemented, it redirects logs here:
https://github.com/tilt-dev/tilt/blob/master/internal/cli/up.go#L135
so that the logs still work no matter what mode you're in.

What if we checked if that flag was set below that line, and logged the message there?

@abdullahzameek
Copy link
Contributor Author

oof, that's frustrating.

if you want to merge this pr as-is and iterate on it, that's fine.

if you look at how tilt up is implemented, it redirects logs here:
https://github.com/tilt-dev/tilt/blob/master/internal/cli/up.go#L135
so that the logs still work no matter what mode you're in.

What if we checked if that flag was set below that line, and logged the message there?

I'm reading through it, I'll try to fix it and then merge it all in one go!

@abdullahzameek
Copy link
Contributor Author

@nicks Managed to put the warning into the logs!

Screenshot from 2020-06-11 23-09-14

If you view it from the TUI though, you see the message being printed twice - once called by flag.go file at https://github.com/tilt-dev/tilt/blob/master/vendor/github.com/spf13/pflag/flag.go#L485 and then again at when the logger output is called. So, if you do --hud=false, you'd see this:
Screenshot from 2020-06-11 23-13-38

I'm not really sure how I can disable the function from the flag.go from printing the warning, other than by modifying the code from there itself, but that seems like a bad idea since its an external library...

cmd.Flag("watch").Deprecated = "it will be removed in future releases."
//if a deprecation message exists, then watch was explicitly set by the user, so mark the watchFlagExplicitlySet var as true for
//logging the message on the web UI and TUI
if len(cmd.Flag("watch").Deprecated) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think this is doing what you expect...this will always be true, because you just set it above.

we probably shouldn't use the Deprecated field at all, because we don't want the flag library to do its own printing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh right, I assumed that the Deprecated property is only invoked when the user explicitly uses the flag in the command line, and that it would just be an empty string otherwise. Turns out that is not the case, my bad.

Yeah, I think I'll look out for another way to do this because of the flag library printing.

(Also, apologies for the late reply, it was getting late yesterday and I was a bit tired)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good now! I got too hung up on utilizing the Deprecated field (since I thought that was the best way to get about it) but turns out, it was just a matter of adding another line under the existing logic:
8ee678d#diff-97a466a66696420cf5da35a819c2d535L106-L112

Its printing the deprecation warning on the logs both on the TUI and the Web UI properly now (and doesn't print the message when the flag isn't present)

Screenshot from 2020-06-12 10-16-47

Screenshot from 2020-06-12 10-17-14

@@ -98,6 +101,7 @@ local resources--i.e. those using serve_cmd--are terminated when you exit Tilt.

cmd.PreRun = func(cmd *cobra.Command, args []string) {
c.hudFlagExplicitlySet = cmd.Flag("hud").Changed
c.watchFlagExplicitlySet = cmd.Flag("watch").Changed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice solution!

@@ -136,6 +140,11 @@ func (c *upCmd) run(ctx context.Context, args []string) error {

logOutput(fmt.Sprintf("Starting Tilt (%s)…", buildStamp()))

//if --watch was set, warn user about deprecation
if c.watchFlagExplicitlySet {
logOutput("Flag --watch has been deprecated, it will be removed in future releases.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, i think you can also use logger.Get(ctx).Warnf(...) if you want it to show up as a warning in the UI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warnf() seems to be doing something interesting - it prints the warning fine on the TUI, but the keyword "warning" doesn't show up on the Web UI for some reason.

Screenshot from 2020-06-12 17-56-14

Screenshot from 2020-06-12 17-57-04

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! it has the yellow UI bar in the web, and skips the prefix

@abdullahzameek abdullahzameek merged commit 329e43f into master Jun 12, 2020
@abdullahzameek abdullahzameek deleted the abdullahzameek/3256-deprecate-watch branch June 12, 2020 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove the --watch flag for tilt up
2 participants