using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;


namespace isn
{
   
    partial class Program
    {
        private static void StoreApiKey(IEnumerable<string> storeArgs)
        {
            var args = storeoptions.Parse(storeArgs);
            if (args.Count != 1)
            {
                Console.Error.WriteLine("StoreApiKey command takse one and only one argument, the key.");
               shouldShowPushHelp=true;
            }
            if (shouldShowPushHelp)
            {
                // output the options
                Console.Error.WriteLine("StoreApiKey Options:");
                storeoptions.WriteOptionDescriptions(Console.Out);
            }
            else
            {
                Settings.Sources[Settings.CurrentSourceKey].SetApiKey(args[0]);
                SaveConfig();
            }
        }

        public static void SaveConfig()
        {
            FileInfo cfgSettingIf = new FileInfo(_configFileName);
            if (!cfgSettingIf.Directory.Exists) cfgSettingIf.Directory.Create();
            File.WriteAllText(
                cfgSettingIf.FullName, 
                JsonConvert.SerializeObject(
                    Settings,
                    Formatting.Indented
            ));
            Console.WriteLine("config saved .");
        }
    }
}