001/*
002 * Syncany, www.syncany.org
003 * Copyright (C) 2011-2016 Philipp C. Heckel <philipp.heckel@gmail.com> 
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU General Public License for more details.
014 *
015 * You should have received a copy of the GNU General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package org.syncany.cli;
019
020import java.util.List;
021
022import org.syncany.operations.OperationOptions;
023import org.syncany.operations.OperationResult;
024import org.syncany.operations.daemon.messages.LsRemoteStartSyncExternalEvent;
025import org.syncany.operations.ls_remote.LsRemoteOperation;
026import org.syncany.operations.ls_remote.LsRemoteOperationResult;
027import org.syncany.plugins.transfer.files.DatabaseRemoteFile;
028import org.syncany.plugins.transfer.files.RemoteFile;
029
030import com.google.common.eventbus.Subscribe;
031
032public class LsRemoteCommand extends Command {
033        @Override
034        public CommandScope getRequiredCommandScope() { 
035                return CommandScope.INITIALIZED_LOCALDIR;
036        }
037        
038        @Override
039        public boolean canExecuteInDaemonScope() {
040                return true;
041        }
042        
043        @Override
044        public int execute(String[] operationArgs) throws Exception {
045                LsRemoteOperationResult operationResult = new LsRemoteOperation(config).execute();
046                printResults(operationResult);          
047                
048                return 0;
049        }
050
051        @Override
052        public OperationOptions parseOptions(String[] operationArgs) throws Exception {         
053                return null;
054        }
055
056        @Override
057        public void printResults(OperationResult operationResult) {
058                LsRemoteOperationResult concreteOperationResult = (LsRemoteOperationResult) operationResult;
059                List<DatabaseRemoteFile> remoteStatus = concreteOperationResult.getUnknownRemoteDatabases();
060                
061                if (remoteStatus.size() > 0) {
062                        for (RemoteFile unknownRemoteFile : remoteStatus) {
063                                out.println("? "+unknownRemoteFile.getName());
064                        }
065                }
066                else {
067                        out.println("No remote changes.");
068                }
069        }       
070        
071        @Subscribe
072        public void onLsRemoteStartEventReceived(LsRemoteStartSyncExternalEvent syncEvent) {
073                out.printr("Checking remote changes ...");
074        }
075}