def _delegate_options(source_options, target_options): target_options.aliases = get_aliases(source_options['node-directory']) target_options["node-url"] = source_options["node-url"] target_options["node-directory"] = source_options["node-directory"] target_options["name"] = source_options["name"] target_options.stdin = MixedIO(u"") target_options.stdout = MixedIO() target_options.stderr = MixedIO() return target_options
def cli(config_directory, argv): """ Perform an in-process equivalent to the given magic-folder command. :param FilePath config_directory: The path to our configuration :param list[bytes] argv: The magic-folder arguments which define the command to run. This does not include "magic-folder" itself, just the following arguments. For example, ``[b"list"]``. :return Deferred[ProcessOutcome]: The side-effects and result of the process. """ options = MagicFolderCommand() options.stdout = MixedIO() options.stderr = MixedIO() try: try: options.parseOptions([ b"--config", config_directory.asBytesMode().path, ] + argv) except UsageError as e: print(e, file=options.stderr) result = 1 else: result = yield run_magic_folder_options(options) if result is None: result = 0 except SystemExit as e: result = e.code Message.log( message_type=u"stdout", value=options.stdout.getvalue(), ) Message.log( message_type=u"stderr", value=options.stderr.getvalue(), ) returnValue( ProcessOutcome( options.stdout.getvalue(), options.stderr.getvalue(), result, ))
class InviteOptions(usage.Options): nickname = None synopsis = "NICKNAME\n\nProduce an invite code for a new device called NICKNAME" stdin = MixedIO(u"") optParameters = [ ("name", "n", None, "Name of an existing magic-folder"), ] description = ( "Invite a new participant to a given magic-folder. The resulting " "invite-code that is printed is secret information and MUST be " "transmitted securely to the invitee.") def parseArgs(self, nickname): super(InviteOptions, self).parseArgs() self.nickname = argv_to_unicode(nickname) def postOptions(self): if self["name"] is None: raise usage.UsageError("Must specify the --name option")
class StatusOptions(BasedirOptions): synopsis = "" stdin = MixedIO(u"") optParameters = [ ("name", "n", "default", "Name for the magic-folder to show status"), ] def parseArgs(self): BasedirOptions.parseArgs(self) node_url_file = os.path.join(self['node-directory'], u"node.url") try: with open(node_url_file, "r") as f: self['node-url'] = f.read().strip() except EnvironmentError as e: raise usage.UsageError( "Could not read node url from {!r}: {!r}".format( node_url_file, e, ))
class InviteOptions(usage.Options): nickname = None synopsis = "MAGIC_ALIAS: NICKNAME" stdin = MixedIO(u"") optParameters = [ ("name", "n", "default", "The name of this magic-folder"), ] description = ( "Invite a new participant to a given magic-folder. The resulting " "invite-code that is printed is secret information and MUST be " "transmitted securely to the invitee.") def parseArgs(self, alias, nickname=None): super(InviteOptions, self).parseArgs() alias = argv_to_unicode(alias) if not alias.endswith(u':'): raise usage.UsageError("An alias must end with a ':' character.") self.alias = alias[:-1] self.nickname = argv_to_unicode(nickname) aliases = get_aliases(self.parent.node_directory) self.aliases = aliases
class InviteOptions(BasedirOptions): nickname = None synopsis = "MAGIC_ALIAS: NICKNAME" stdin = MixedIO(u"") optParameters = [ ("name", "n", "default", "The name of this magic-folder"), ] description = ( "Invite a new participant to a given magic-folder. The resulting " "invite-code that is printed is secret information and MUST be " "transmitted securely to the invitee.") def parseArgs(self, alias, nickname=None): BasedirOptions.parseArgs(self) alias = argv_to_unicode(alias) if not alias.endswith(u':'): raise usage.UsageError("An alias must end with a ':' character.") self.alias = alias[:-1] self.nickname = argv_to_unicode(nickname) node_url_file = os.path.join(self['node-directory'], u"node.url") self['node-url'] = open(node_url_file, "r").read().strip() aliases = get_aliases(self['node-directory']) self.aliases = aliases
class StatusOptions(usage.Options): synopsis = "" stdin = MixedIO(u"") optParameters = [ ("name", "n", "default", "Name for the magic-folder to show status"), ]