Skip to content

Refactor CLI code to allow passing CLI arguments via function parameter - #8485

Merged
calmh merged 1 commit into
syncthing:mainfrom
Martchus:refactor-cli
Aug 7, 2022
Merged

calmh merged 1 commit into
syncthing:mainfrom
Martchus:refactor-cli

Conversation

@Martchus

@Martchus Martchus commented Aug 4, 2022

Copy link
Copy Markdown
Contributor

Currently the Run() function of the CLI always uses os.Args directly.
This change adds an additional RunWithArgs() function that allows passing
arguments as []string instead.

Purpose

This is useful when linking against Syncthing as a library to be able to also
expose the CLI. For instance, this is used by
Syncthing Tray which can have
Syncthing as built-in library. Like Syncthing itself it then features the cli
sub-command exposing Syncthing's CLI.

Testing

This change has been tested manually within the context of Syncthing Tray. It
is actually already part of recent Syncthing Tray releases (relevant commit is
in my forked Syncthing repository used by Syncthing Tray as submodule, e.g.
Martchus@ced426e).
The Syncthing Tray binaries on GitHub
have the feature enabled if one wants to check.

I have also added a rudimentary unit/integration test on my side (see
https://github.com/Martchus/syncthingtray/blob/6f0c5af8fc3fd56c9084a35729b69fe33f624257/libsyncthing/tests/interfacetests.cpp#L260).

Syncthing's own behavior should remain unaffected by the refactoring so
I hope that extending its test suite is not necessary.

Screenshots

The GUI wrapper behaves like Syncthing itself when attempting to use the CLI. That looks quite neat:
Screenshot_20220804_184603

Currently the `Run()` function of the CLI always uses `os.Args` directly.
This change adds an additional `RunWithArgs()` function that allows passing
arguments as `[]string` instead. This is useful when linking against
Syncthing as a library to be able to also expose the CLI.
@calmh
calmh merged commit 373859b into syncthing:main Aug 7, 2022
@Martchus
Martchus deleted the refactor-cli branch August 7, 2022 16:24
calmh added a commit to calmh/syncthing that referenced this pull request Aug 8, 2022
* main:
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Refactor CLI code to allow passing CLI arguments via function parameter (syncthing#8485)
@calmh calmh added this to the v1.21.0 milestone Aug 9, 2022
calmh added a commit to acolomb/syncthing that referenced this pull request Aug 10, 2022
* main:
  build: bump actions/setup-go from 2.2.0 to 3.2.1 (syncthing#8492)
  build: Let dependabot suggest updates to GitHub actions (syncthing#8490)
  update: Go version in update-docs-translations action (syncthing#8489)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Refactor CLI code to allow passing CLI arguments via function parameter (syncthing#8485)
  build: Update quic-go for Go 1.19 (syncthing#8483)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479) (syncthing#8480)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479)
calmh added a commit to tomasz1986/syncthing that referenced this pull request Aug 10, 2022
* main: (94 commits)
  build: bump actions/setup-go from 2.2.0 to 3.2.1 (syncthing#8492)
  build: Let dependabot suggest updates to GitHub actions (syncthing#8490)
  update: Go version in update-docs-translations action (syncthing#8489)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Refactor CLI code to allow passing CLI arguments via function parameter (syncthing#8485)
  build: Update quic-go for Go 1.19 (syncthing#8483)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479) (syncthing#8480)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479)
  gui, man, authors: Update docs, translations, and contributors
  docs: Clarify docker network mode limitations (syncthing#8472)
  lib/config: Use net.JoinHostPort instead of string manipulation (syncthing#8470)
  lib/api: Fix inverted logic in string comparison
  lib/model: Use bytes.Equal instead of converting to string (syncthing#8469)
  all: Add build constants for runtime.GOOS comparisons (syncthing#8442)
  cmd/strelaysrv: Fix superfluous else statements (syncthing#8468)
  all: Fix nested `if` with `else if` (syncthing#8467)
  all: Unused errors
  lib/fs: Consolidate append in test
  lib/api: Further (final?) unused parameters removal
  cmd/syncthing: Incorrect error handling
  ...
calmh added a commit to acolomb/syncthing that referenced this pull request Aug 10, 2022
* main: (121 commits)
  gui, api: Show internal config and state paths (fixes syncthing#8323) (syncthing#8324)
  build(deps): bump github.com/go-ldap/ldap/v3 from 3.4.1 to 3.4.4 (syncthing#8475)
  build: bump actions/setup-go from 2.2.0 to 3.2.1 (syncthing#8492)
  build: Let dependabot suggest updates to GitHub actions (syncthing#8490)
  update: Go version in update-docs-translations action (syncthing#8489)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Refactor CLI code to allow passing CLI arguments via function parameter (syncthing#8485)
  build: Update quic-go for Go 1.19 (syncthing#8483)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479) (syncthing#8480)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479)
  gui, man, authors: Update docs, translations, and contributors
  docs: Clarify docker network mode limitations (syncthing#8472)
  lib/config: Use net.JoinHostPort instead of string manipulation (syncthing#8470)
  lib/api: Fix inverted logic in string comparison
  lib/model: Use bytes.Equal instead of converting to string (syncthing#8469)
  all: Add build constants for runtime.GOOS comparisons (syncthing#8442)
  cmd/strelaysrv: Fix superfluous else statements (syncthing#8468)
  all: Fix nested `if` with `else if` (syncthing#8467)
  all: Unused errors
  lib/fs: Consolidate append in test
  ...
calmh added a commit to calmh/syncthing that referenced this pull request Aug 18, 2022
* main: (256 commits)
  cmd/syncthing: Use os.executable in monitor, only fallback to PATH (syncthing#8502)
  all: Modernize error wrapping (syncthing#8491)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Work around binary in current dir restriction (fixes syncthing#8499) (syncthing#8500)
  lib/fs: Cache user lookups (syncthing#8496)
  all: Make scanning ownership opt-in (syncthing#8497)
  lib/model: Skip paused folders in aggregated completion loop (fixes syncthing#8219) (syncthing#8220)
  gui: Remove unused strings from translations (syncthing#8288)
  gui, api: Show internal config and state paths (fixes syncthing#8323) (syncthing#8324)
  build(deps): bump github.com/go-ldap/ldap/v3 from 3.4.1 to 3.4.4 (syncthing#8475)
  build: bump actions/setup-go from 2.2.0 to 3.2.1 (syncthing#8492)
  build: Let dependabot suggest updates to GitHub actions (syncthing#8490)
  update: Go version in update-docs-translations action (syncthing#8489)
  gui, man, authors: Update docs, translations, and contributors
  cmd/syncthing: Refactor CLI code to allow passing CLI arguments via function parameter (syncthing#8485)
  build: Update quic-go for Go 1.19 (syncthing#8483)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479) (syncthing#8480)
  lib/ur: Properly initialize map in failure data (fixes syncthing#8479)
  gui, man, authors: Update docs, translations, and contributors
  docs: Clarify docker network mode limitations (syncthing#8472)
  ...
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Aug 7, 2023
@syncthing syncthing locked and limited conversation to collaborators Aug 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants