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

CLI improvements proposal: positional argument #65

Closed
wants to merge 15 commits into from

Conversation

happyRip
Copy link
Member

@happyRip happyRip commented Jan 5, 2023

Summary

Closes #56

Changes

  • Add an optional positional source argument (pkg/arg)

  • Print only source-related flags with those commands

    • Removed prefixes from ttnv3 flags; to be followed with other sources
  • Split application and devices commands FlagSets

  • Improved ttnv3 config by utilising flags that save value to variables directly

Testing

local testing

  • The Things Stack
  • Chirpstack v3
  • ttnv2
Regressions

I do not expect any.

Notes for Reviewers

  • If we were planning to add more commands in the future, FlagSet splitting could be upgraded to a more sophisticated solution. Currently it's pretty simple.

  • It was suggested to use generated commands like tts-devices ETC, but I wanted to propose this solution which seems to work well and is pretty simple

  • When pflag is used to set ActiveSource the value is set after initialisation, so the flags cannot be separated easily (during FlagSet() function call)

Checklist

  • Scope: The referenced issue is addressed, there are no unrelated changes.
  • Documentation: Relevant documentation is added or updated.
  • Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.

@happyRip happyRip self-assigned this Jan 5, 2023
@happyRip happyRip force-pushed the feature/56-cli-redesign branch 3 times, most recently from cc5d0f6 to 618f047 Compare January 9, 2023 13:12
@happyRip happyRip marked this pull request as ready for review January 9, 2023 14:09
@happyRip happyRip added this to the v0.10.0 milestone Jan 9, 2023
@happyRip happyRip marked this pull request as draft January 10, 2023 11:11
@happyRip happyRip force-pushed the feature/56-cli-redesign branch 2 times, most recently from b1813a4 to 0f8a43e Compare January 17, 2023 16:10
@happyRip happyRip force-pushed the feature/56-cli-redesign branch 3 times, most recently from 5a8c694 to b93c2e5 Compare February 19, 2023 16:21
)

flags.StringVar(&config.AppID,
devices.StringVar(&config.AppID,
Copy link
Member Author

Choose a reason for hiding this comment

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

The --app-id flag was removed from application command of ttnv{2,3} sources since there was no use case for it.
Example:

ttn-lw-migrate ttnv3 application --app-id 'my-app'

If the tool was called like this without an argument it would expect to receive Application IDs from stdin so the flag would be ignored and the tool would 'hang unexpectedly' (waiting).

Since f33a68b the argument always overrides the flag. This combination makes the flag redundant or even confusing for the application command in those sources.

@happyRip happyRip marked this pull request as ready for review February 20, 2023 16:00
Copy link
Member

@johanstokking johanstokking left a comment

Choose a reason for hiding this comment

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

Is this flag magic really necessary? Why don't we have commands per source with their own flag sets?

Also I see some exotic use of switch/case while this is what simple if/else statements seem to be made for.

@adriansmares
Copy link
Contributor

Is this flag magic really necessary? Why don't we have commands per source with their own flag sets?

@happyRip I think this actually may be better than our current hack. We would need to generate dynamically an application / device sub command per source, but I think it would indeed work better here.

CHANGELOG.md Outdated
@@ -8,24 +8,31 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Added

- Added `--ttnv3.no-session` and `--ttnv3.delete-source-device` flags
- positional `source` argument
Copy link
Contributor

Choose a reason for hiding this comment

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

Upper case first letter and dot at the end.

CHANGELOG.md Outdated

### Changed

### Fixed
- depreciated `--source` flag
Copy link
Contributor

Choose a reason for hiding this comment

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

Upper case first letter, deprecated and dot at the end.

CHANGELOG.md Outdated

### Removed

- `--app-id` flag for `application` command
Copy link
Contributor

Choose a reason for hiding this comment

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

Dot at the end. Same below.

return err
}

// deleteSourceDevice not allowed when dryRun
Copy link
Contributor

Choose a reason for hiding this comment

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

DeleteSourceDevice is not allowed during a dry run.

pkg/source/ttnv3/util.go Outdated Show resolved Hide resolved
@happyRip happyRip mentioned this pull request Mar 2, 2023
3 tasks
@happyRip happyRip marked this pull request as draft March 8, 2023 12:39
@adriansmares
Copy link
Contributor

What is the status here - is this blocked on anything ? Does it need any technical decision ?

@happyRip happyRip changed the title Migration tool CLI improvements CLI improvements proposal: positional argument May 1, 2023
@happyRip
Copy link
Member Author

happyRip commented May 1, 2023

Subcommands approach was merged, so this PR can be closed.

@happyRip happyRip closed this May 1, 2023
@johanstokking johanstokking deleted the feature/56-cli-redesign branch May 2, 2023 12:04
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.

Migration tool CLI redesign
3 participants